Class: HealthSeven::Message::Segment
- Inherits:
-
Object
- Object
- HealthSeven::Message::Segment
- Defined in:
- lib/health_seven/message.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #[](field, subfield = nil) ⇒ Object
-
#initialize ⇒ Segment
constructor
A new instance of Segment.
- #method_missing(method_name, *args) ⇒ Object
Constructor Details
#initialize ⇒ Segment
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
#children ⇒ Object
Returns the value of attribute children.
163 164 165 |
# File 'lib/health_seven/message.rb', line 163 def children @children end |
#fields ⇒ Object
Returns the value of attribute fields.
162 163 164 |
# File 'lib/health_seven/message.rb', line 162 def fields @fields end |
#name ⇒ Object
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 |