Class: MediServ::API::Node
- Inherits:
-
Object
- Object
- MediServ::API::Node
- Includes:
- Format
- Defined in:
- lib/mediserv/api/encoder.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name: nil, attributes: {}, children: []) ⇒ Node
constructor
A new instance of Node.
- #to_ini(io = StringIO.new) ⇒ Object
Methods included from Format
#fmt_amount, #fmt_date, #fmt_string, #fmt_time
Constructor Details
#initialize(name: nil, attributes: {}, children: []) ⇒ Node
Returns a new instance of Node.
29 30 31 32 33 |
# File 'lib/mediserv/api/encoder.rb', line 29 def initialize(name: nil, attributes: {}, children: []) @name = name @attributes = attributes @children = children end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
27 28 29 |
# File 'lib/mediserv/api/encoder.rb', line 27 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children.
27 28 29 |
# File 'lib/mediserv/api/encoder.rb', line 27 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/mediserv/api/encoder.rb', line 27 def name @name end |
Instance Method Details
#to_ini(io = StringIO.new) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mediserv/api/encoder.rb', line 35 def to_ini(io = StringIO.new) if name io << '[' io << name io << ']' io << "\n" end attributes.each do |k, v| next unless k && v io << k.to_s io << '=' v = case v when Float io << fmt_amount(v) when String io << v.tr("\n", '') else io << v end io << "\n" end children.each do |c| io << "\n" c.to_ini(io) end io.string.encode('windows-1252') end |