Class: Pipehat::Message
- Inherits:
-
Object
- Object
- Pipehat::Message
- Defined in:
- lib/pipehat/message.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
- #<<(segment) ⇒ Object
-
#initialize(hl7 = "", parser: Pipehat::DEFAULT_PARSER) ⇒ Message
constructor
A new instance of Message.
-
#segments(type = nil) ⇒ Object
Returns an enumerator over the message’s segments The optional parameter limits it to the given type.
- #to_hl7 ⇒ Object
Constructor Details
#initialize(hl7 = "", parser: Pipehat::DEFAULT_PARSER) ⇒ Message
Returns a new instance of Message.
5 6 7 8 |
# File 'lib/pipehat/message.rb', line 5 def initialize(hl7 = "", parser: Pipehat::DEFAULT_PARSER) @parser = parser @segments = parser.parse(hl7) end |
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
10 11 12 |
# File 'lib/pipehat/message.rb', line 10 def parser @parser end |
Instance Method Details
#<<(segment) ⇒ Object
16 17 18 |
# File 'lib/pipehat/message.rb', line 16 def <<(segment) @segments << segment end |
#segments(type = nil) ⇒ Object
Returns an enumerator over the message’s segments The optional parameter limits it to the given type
22 23 24 25 26 27 28 29 30 |
# File 'lib/pipehat/message.rb', line 22 def segments(type = nil) return to_enum(:segments, type) unless block_given? @segments.each do |segment| next if type && segment.segment_name != type.to_s yield segment end end |
#to_hl7 ⇒ Object
12 13 14 |
# File 'lib/pipehat/message.rb', line 12 def to_hl7 segments.map(&:to_hl7).join(parser.segment_sep) end |