Class: Stupidedi::Reader::Separators

Inherits:
Object
  • Object
show all
Defined in:
lib/stupidedi/reader/separators.rb

Overview

Stores the separators used to tokenize X12 from an input stream and serialize it to an output stream.

See Also:

  • B.1.1.2.5 Delimiters

Instance Attribute Summary collapse

Constructors collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, repetition, element, segment) ⇒ Separators

Returns a new instance of Separators.



26
27
28
29
# File 'lib/stupidedi/reader/separators.rb', line 26

def initialize(component, repetition, element, segment)
  @component, @repetition, @element, @segment =
    component, repetition, element, segment
end

Instance Attribute Details

#componentString

Returns:

  • (String)


15
16
17
# File 'lib/stupidedi/reader/separators.rb', line 15

def component
  @component
end

#elementString

Returns:

  • (String)


21
22
23
# File 'lib/stupidedi/reader/separators.rb', line 21

def element
  @element
end

#repetitionString

Returns:

  • (String)


18
19
20
# File 'lib/stupidedi/reader/separators.rb', line 18

def repetition
  @repetition
end

#segmentString

Returns:

  • (String)


24
25
26
# File 'lib/stupidedi/reader/separators.rb', line 24

def segment
  @segment
end

Class Method Details

.build(hash) ⇒ Separators

Returns:



74
75
76
77
78
79
80
# File 'lib/stupidedi/reader/separators.rb', line 74

def build(hash)
  Separators.new \
    hash[:component],
    hash[:repetition],
    hash[:element],
    hash[:segment]
end

.emptySeparators

Returns:



69
70
71
# File 'lib/stupidedi/reader/separators.rb', line 69

def empty
  new(nil, nil, nil, nil)
end

Instance Method Details

#charactersAbstractSet<String>

Returns:

  • (AbstractSet<String>)


51
52
53
54
55
56
# File 'lib/stupidedi/reader/separators.rb', line 51

def characters
  chars =
    [@component, @repetition, @element, @segment].select(&:present?)

  Sets.absolute(chars.join.split(//), Reader::C_BYTES.split(//))
end

#copy(changes = {}) ⇒ Separators

Returns:



32
33
34
35
36
37
38
# File 'lib/stupidedi/reader/separators.rb', line 32

def copy(changes = {})
  Separators.new \
    changes.fetch(:component, @component),
    changes.fetch(:repetition, @repetition),
    changes.fetch(:element, @element),
    changes.fetch(:segment, @segment)
end

#inspectString

Returns:

  • (String)


59
60
61
# File 'lib/stupidedi/reader/separators.rb', line 59

def inspect
  "Separators(#{@component.inspect}, #{@repetition.inspect}, #{@element.inspect}, #{@segment.inspect})"
end

#merge(other) ⇒ Object

Creates a new value that has the separators from ‘other`, when they are not nil, and will use separators from `self` otherwise.



42
43
44
45
46
47
48
# File 'lib/stupidedi/reader/separators.rb', line 42

def merge(other)
  Separators.new \
    other.component  || @component,
    other.repetition || @repetition,
    other.element    || @element,
    other.segment    || @segment
end