Module: Jaspion::Kilza::Class
- Included in:
- Java::Class, Objc::Class, Swift::Class
- Defined in:
- lib/jaspion/kilza/class.rb
Overview
Represents one single object class
Instance Attribute Summary collapse
-
#name ⇒ Object
Class name.
-
#properties ⇒ Object
Array with all class properties.
Instance Method Summary collapse
-
#code(lang, file_name) ⇒ Kilza::Source
Returns the #Source object of this Class.
-
#delete_import(import) ⇒ Object
Removes an new import statement.
- #imports ⇒ Object
-
#initialize(name) ⇒ Object
Initializes a Class object.
-
#push(property) ⇒ Object
Adds a new property.
-
#push_import(import) ⇒ Object
Adds an new import statement.
- #sources ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#name ⇒ Object
Class name
6 7 8 |
# File 'lib/jaspion/kilza/class.rb', line 6 def name @name end |
#properties ⇒ Object
Array with all class properties
9 10 11 |
# File 'lib/jaspion/kilza/class.rb', line 9 def properties @properties end |
Instance Method Details
#code(lang, file_name) ⇒ Kilza::Source
Returns the #Source object of this Class.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jaspion/kilza/class.rb', line 48 def code(lang, file_name) cur_path = File.(__FILE__) erb_path = File.join(File.dirname(cur_path), 'language', lang) path = File.join(erb_path, file_name + '.erb') eruby = Erubis::Eruby.new(File.read(path)) s = Kilza::Source.new s.source = eruby.result(binding) s.file_name = @name + '.' + file_name s end |
#delete_import(import) ⇒ Object
Removes an new import statement
84 85 86 87 88 |
# File 'lib/jaspion/kilza/class.rb', line 84 def delete_import(import) import = [import] if import.is_a? String i = @imports.index(import) @imports.delete_at(i) unless i.nil? end |
#imports ⇒ Object
21 22 23 |
# File 'lib/jaspion/kilza/class.rb', line 21 def imports @imports.sort.separate.flatten end |
#initialize(name) ⇒ Object
Initializes a Class object
14 15 16 17 18 19 |
# File 'lib/jaspion/kilza/class.rb', line 14 def initialize(name) @name = Jaspion::Kilza::Class.normalize(name) # @name[0] = @name[0].capitalize @properties = [] @imports = [] end |
#push(property) ⇒ Object
Adds a new property
28 29 30 31 32 33 34 35 36 |
# File 'lib/jaspion/kilza/class.rb', line 28 def push(property) index = @properties.index(property) unless index.nil? current = @properties[index] @properties[index] = update(current, property) else @properties.push(property) end end |
#push_import(import) ⇒ Object
Adds an new import statement
75 76 77 78 79 |
# File 'lib/jaspion/kilza/class.rb', line 75 def push_import(import) import = [import] if import.is_a? String index = @imports.index(import) @imports.push(import) if index.nil? end |
#sources ⇒ Object
38 39 40 |
# File 'lib/jaspion/kilza/class.rb', line 38 def sources fail 'It should be implemented' end |
#to_s ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/jaspion/kilza/class.rb', line 61 def to_s properties = [] @properties.each { |p| properties.push(p.to_s) } { name: @name, imports: @imports, properties: properties }.to_s end |