Class: HL7::Message::SegmentGenerator
- Inherits:
-
Object
- Object
- HL7::Message::SegmentGenerator
- Defined in:
- lib/segment_generator.rb
Overview
Methods for creating segments in Message
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#last_seg ⇒ Object
readonly
Returns the value of attribute last_seg.
-
#seg_name ⇒ Object
Returns the value of attribute seg_name.
-
#seg_parts ⇒ Object
Returns the value of attribute seg_parts.
Instance Method Summary collapse
- #build ⇒ Object
- #get_segment_class ⇒ Object
-
#initialize(element, last_seg, delimiter) ⇒ SegmentGenerator
constructor
A new instance of SegmentGenerator.
- #valid_segments_parts? ⇒ Boolean
Constructor Details
#initialize(element, last_seg, delimiter) ⇒ SegmentGenerator
Returns a new instance of SegmentGenerator.
20 21 22 23 24 25 26 27 |
# File 'lib/segment_generator.rb', line 20 def initialize(element, last_seg, delimiter) @element = element @last_seg = last_seg @delimiter = delimiter @seg_parts = HL7::MessageParser.split_by_delimiter(element, delimiter.element) end |
Instance Attribute Details
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter.
16 17 18 |
# File 'lib/segment_generator.rb', line 16 def delimiter @delimiter end |
#element ⇒ Object (readonly)
Returns the value of attribute element.
16 17 18 |
# File 'lib/segment_generator.rb', line 16 def element @element end |
#last_seg ⇒ Object (readonly)
Returns the value of attribute last_seg.
16 17 18 |
# File 'lib/segment_generator.rb', line 16 def last_seg @last_seg end |
#seg_name ⇒ Object
Returns the value of attribute seg_name.
18 19 20 |
# File 'lib/segment_generator.rb', line 18 def seg_name @seg_name end |
#seg_parts ⇒ Object
Returns the value of attribute seg_parts.
18 19 20 |
# File 'lib/segment_generator.rb', line 18 def seg_parts @seg_parts end |
Instance Method Details
#build ⇒ Object
37 38 39 40 |
# File 'lib/segment_generator.rb', line 37 def build klass = get_segment_class klass.new(@element, [@delimiter.element, @delimiter.item]) end |
#get_segment_class ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/segment_generator.rb', line 42 def get_segment_class segment_to_search = @seg_name.to_sym segment_to_search = @seg_name if RUBY_VERSION < "1.9" if HL7::Message::Segment.constants.index(segment_to_search) eval(format("HL7::Message::Segment::%s", @seg_name)) else HL7::Message::Segment::Default end end |
#valid_segments_parts? ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'lib/segment_generator.rb', line 29 def valid_segments_parts? return true if @seg_parts&.length&.positive? raise HL7::EmptySegmentNotAllowed if HL7.configuration.empty_segment_is_error false end |