Class: REX12::Element
- Inherits:
-
Object
- Object
- REX12::Element
- Defined in:
- lib/rex12/element.rb
Instance Attribute Summary collapse
-
#position ⇒ Integer
readonly
Zero based location of this element in its parent segment.
-
#value ⇒ String
readonly
Base text value of the element (does not break up sub elements).
Instance Method Summary collapse
-
#initialize(value, sub_element_separator, position) ⇒ Element
constructor
A new instance of Element.
-
#sub_elements ⇒ Array<String>?
Get all sub elements as an array or yield them to a block.
-
#sub_elements? ⇒ true, false
Does the element have sub elements.
Constructor Details
#initialize(value, sub_element_separator, position) ⇒ Element
Returns a new instance of Element.
12 13 14 15 16 |
# File 'lib/rex12/element.rb', line 12 def initialize value, sub_element_separator, position @value = value @sub_element_separator = sub_element_separator @position = position end |
Instance Attribute Details
#position ⇒ Integer (readonly)
Returns zero based location of this element in its parent segment.
7 8 9 |
# File 'lib/rex12/element.rb', line 7 def position @position end |
#value ⇒ String (readonly)
Returns base text value of the element (does not break up sub elements).
4 5 6 |
# File 'lib/rex12/element.rb', line 4 def value @value end |
Instance Method Details
#sub_elements ⇒ Array<String>?
Get all sub elements as an array or yield them to a block
25 26 27 28 29 30 31 32 |
# File 'lib/rex12/element.rb', line 25 def sub_elements r = @value.split(@sub_element_separator) if block_given? r.each {|se| yield se} return nil end return r end |
#sub_elements? ⇒ true, false
Returns does the element have sub elements.
19 20 21 |
# File 'lib/rex12/element.rb', line 19 def sub_elements? @value.index(@sub_element_separator) ? true : false end |