class MediServ::API::Node

Attributes

attributes[RW]
children[RW]
name[RW]

Public Class Methods

new(name: nil, attributes: {}, children: []) click to toggle source
# File lib/mediserv/api/encoder.rb, line 29
def initialize(name: nil, attributes: {}, children: [])
  @name = name
  @attributes = attributes
  @children = children
end

Public Instance Methods

to_ini(io = StringIO.new) click to toggle source
# 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