class YAHL7::V2::ParseOptions

This class defines the parse options used for an HL7 message. This should be generated by the HL7 message itself, but it is possible to define one manually, as well.

Attributes

component_sep[RW]
escape[RW]
field_sep[RW]
repetition_sep[RW]
segment_sep[RW]
sub_component_sep[RW]

Public Class Methods

from_body(body, segment_sep = "\r") click to toggle source

HL7 messages embed their own parse options in the message (with the exception of the segment separator, which should always be a return, but some systems do not always use this).

# File lib/yahl7/v2/parse_options.rb, line 36
def self.from_body(body, segment_sep = "\r")
  new(
    segment_sep: segment_sep,
    repetition_sep: body[3],
    component_sep: body[4],
    field_sep: body[5],
    escape: body[6],
    sub_component_sep: body[7]
  )
end
new( segment_sep: YAHL7::V2::SEGMENT_SEP, repetition_sep: YAHL7::V2::REPETITION_SEP, field_sep: YAHL7::V2::FIELD_SEP, component_sep: YAHL7::V2::COMPONENT_SEP, sub_component_sep: YAHL7::V2::SUB_COMPONENT_SEP, escape: YAHL7::V2::ESCAPE ) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/yahl7/v2/parse_options.rb, line 12
def initialize(
  segment_sep: YAHL7::V2::SEGMENT_SEP,
  repetition_sep: YAHL7::V2::REPETITION_SEP,
  field_sep: YAHL7::V2::FIELD_SEP,
  component_sep: YAHL7::V2::COMPONENT_SEP,
  sub_component_sep: YAHL7::V2::SUB_COMPONENT_SEP,
  escape: YAHL7::V2::ESCAPE
)
  @segment_sep = segment_sep
  @repetition_sep = repetition_sep
  @field_sep = field_sep
  @component_sep = component_sep
  @sub_component_sep = sub_component_sep
  @escape = escape
end

Public Instance Methods

field_regexp() click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/yahl7/v2/parse_options.rb, line 29
def field_regexp
  /#{Regexp.escape(field_sep)}|#{Regexp.escape(component_sep)}|#{Regexp.escape(sub_component_sep)}/
end