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.



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

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

Instance Attribute Details

#componentString

Returns:

  • (String)


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

def component
  @component
end

#elementString

Returns:

  • (String)


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

def element
  @element
end

#repetitionString

Returns:

  • (String)


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

def repetition
  @repetition
end

#segmentString

Returns:

  • (String)


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

def segment
  @segment
end

Class Method Details

.build(hash) ⇒ Separators

Returns:



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

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

.defaultSeparators

Returns:



82
83
84
# File 'lib/stupidedi/reader/separators.rb', line 82

def default
  Separators.new(":", "^", "*", "~")
end

.emptySeparators

Returns:



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

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

Instance Method Details

#charactersAbstractSet<String>

Returns:

  • (AbstractSet<String>)


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

def characters
  chars =
    [@component, @repetition, @element, @segment].select{|s| s.present? }

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

#copy(changes = {}) ⇒ Separators

Returns:



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

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)


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

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

#merge(other)

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



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

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