Class: Eancom::Parser::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/eancom/parser/segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Segment

Returns a new instance of Segment.



7
8
9
10
11
12
# File 'lib/eancom/parser/segment.rb', line 7

def initialize(string)
  @string = string
  @components = []
  @tag = una? ? 'UNA' : string.split(data_delimiter)[0]
  @segment_class = find_segment_class
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



5
6
7
# File 'lib/eancom/parser/segment.rb', line 5

def components
  @components
end

#segment_classObject

Returns the value of attribute segment_class.



5
6
7
# File 'lib/eancom/parser/segment.rb', line 5

def segment_class
  @segment_class
end

#stringObject

Returns the value of attribute string.



5
6
7
# File 'lib/eancom/parser/segment.rb', line 5

def string
  @string
end

#tagObject

Returns the value of attribute tag.



5
6
7
# File 'lib/eancom/parser/segment.rb', line 5

def tag
  @tag
end

Instance Method Details

#parseObject



14
15
16
17
18
19
# File 'lib/eancom/parser/segment.rb', line 14

def parse
  parse_component
  klass = find_segment_class
  structure = find_structure
  klass.initialize_by_components(structure, @components)
end