Class: Xml2Go::Struct
- Inherits:
-
Object
- Object
- Xml2Go::Struct
- Defined in:
- lib/xml2go/struct.rb
Overview
class representing a Go struct
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#add_field(var_name, type, xml_tag, value = nil) ⇒ Object
adds member variable to struct.
-
#delete_field(var_name) ⇒ Object
adds member variable to struct.
- #get_consts ⇒ Object
-
#initialize(type) ⇒ Struct
constructor
A new instance of Struct.
- #to_declaration ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type) ⇒ Struct
Returns a new instance of Struct.
38 39 40 41 |
# File 'lib/xml2go/struct.rb', line 38 def initialize(type) @type = type @fields = {} end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
36 37 38 |
# File 'lib/xml2go/struct.rb', line 36 def fields @fields end |
#type ⇒ Object
Returns the value of attribute type.
36 37 38 |
# File 'lib/xml2go/struct.rb', line 36 def type @type end |
Instance Method Details
#add_field(var_name, type, xml_tag, value = nil) ⇒ Object
adds member variable to struct
44 45 46 |
# File 'lib/xml2go/struct.rb', line 44 def add_field(var_name, type, xml_tag, value=nil) @fields[var_name] = Field.new(var_name, type, xml_tag, value) end |
#delete_field(var_name) ⇒ Object
adds member variable to struct
49 50 51 |
# File 'lib/xml2go/struct.rb', line 49 def delete_field(var_name) @fields.delete(var_name) end |
#get_consts ⇒ Object
68 69 70 71 |
# File 'lib/xml2go/struct.rb', line 68 def get_consts consts_string = @fields.values.map{ |v| v.to_const} "// #{@type} info \n" << consts_string.join("\n") end |
#to_declaration ⇒ Object
61 62 63 64 65 66 |
# File 'lib/xml2go/struct.rb', line 61 def to_declaration fields_string = @fields.values.map { |v| v.to_declaration} "#{Xml2Go::low(@type)} := #{@type} { #{fields_string.join("\n")} }" end |
#to_s ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/xml2go/struct.rb', line 53 def to_s fields_string = @fields.values.join("\n") "type #{@type} struct {\n #{fields_string} } " end |