Class: REX12::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/rex12/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, sub_element_separator, position) ⇒ Element

Returns a new instance of Element.

Parameters:

  • value (String)

    base text value of the element

  • sub_element_separator (String)

    character that should be used to split sub elements

  • position (Integer)

    zero based position of this element in its parent segment



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

#positionInteger (readonly)

Returns zero based location of this element in its parent segment.

Returns:

  • (Integer)

    zero based location of this element in its parent segment



7
8
9
# File 'lib/rex12/element.rb', line 7

def position
  @position
end

#valueString (readonly)

Returns base text value of the element (does not break up sub elements).

Returns:

  • (String)

    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_elementsArray<String>?

Get all sub elements as an array or yield them to a block

Returns:

  • (Array<String>, nil)


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.

Returns:

  • (true, false)

    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