Class: HealthSeven::Message::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/health_seven/message.rb

Direct Known Subclasses

Message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSegment

Returns a new instance of Segment.



165
166
167
# File 'lib/health_seven/message.rb', line 165

def initialize
  @children = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



169
170
171
172
173
174
175
176
177
178
# File 'lib/health_seven/message.rb', line 169

def method_missing(method_name, *args)
  res = nil
  if method_name.length == 3
    res = @children.find { |segment| segment.name == method_name.to_s.upcase }
  else
    res = @children.select { |segment| segment.name == method_name.to_s[0..2].upcase }
  end

  return res
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



163
164
165
# File 'lib/health_seven/message.rb', line 163

def children
  @children
end

#fieldsObject

Returns the value of attribute fields.



162
163
164
# File 'lib/health_seven/message.rb', line 162

def fields
  @fields
end

#nameObject

Returns the value of attribute name.



161
162
163
# File 'lib/health_seven/message.rb', line 161

def name
  @name
end

Instance Method Details

#[](field, subfield = nil) ⇒ Object



180
181
182
183
184
185
186
187
# File 'lib/health_seven/message.rb', line 180

def [](field, subfield = nil)
  f = fields.split('|')[field - 1]
  if subfield
    f.split('^')[subfield - 1]
  else
    f
  end
end