Class: Stupidedi::Reader::Separators
- Inherits:
-
Object
- Object
- Stupidedi::Reader::Separators
- 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.
Instance Attribute Summary collapse
Constructors collapse
Instance Method Summary collapse
- #characters ⇒ AbstractSet<String>
- #copy(changes = {}) ⇒ Separators
-
#initialize(component, repetition, element, segment) ⇒ Separators
constructor
A new instance of Separators.
- #inspect ⇒ String
-
#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.
Constructor Details
#initialize(component, repetition, element, segment) ⇒ Separators
Returns a new instance of Separators.
28 29 30 31 |
# File 'lib/stupidedi/reader/separators.rb', line 28 def initialize(component, repetition, element, segment) @component, @repetition, @element, @segment = component, repetition, element, segment end |
Instance Attribute Details
#component ⇒ String
17 18 19 |
# File 'lib/stupidedi/reader/separators.rb', line 17 def component @component end |
#element ⇒ String
23 24 25 |
# File 'lib/stupidedi/reader/separators.rb', line 23 def element @element end |
#repetition ⇒ String
20 21 22 |
# File 'lib/stupidedi/reader/separators.rb', line 20 def repetition @repetition end |
#segment ⇒ String
26 27 28 |
# File 'lib/stupidedi/reader/separators.rb', line 26 def segment @segment end |
Class Method Details
.build(hash) ⇒ Separators
76 77 78 79 80 81 82 |
# File 'lib/stupidedi/reader/separators.rb', line 76 def build(hash) Separators.new \ hash[:component], hash[:repetition], hash[:element], hash[:segment] end |
.empty ⇒ Separators
71 72 73 |
# File 'lib/stupidedi/reader/separators.rb', line 71 def empty new(nil, nil, nil, nil) end |
Instance Method Details
#characters ⇒ AbstractSet<String>
53 54 55 56 57 58 |
# File 'lib/stupidedi/reader/separators.rb', line 53 def characters chars = [@component, @repetition, @element, @segment].select{|s| s.present? } Sets.absolute(chars.join.split(//), Reader::C_BYTES.split(//)) end |
#copy(changes = {}) ⇒ Separators
34 35 36 37 38 39 40 |
# File 'lib/stupidedi/reader/separators.rb', line 34 def copy(changes = {}) Separators.new \ changes.fetch(:component, @component), changes.fetch(:repetition, @repetition), changes.fetch(:element, @element), changes.fetch(:segment, @segment) end |
#inspect ⇒ String
61 62 63 |
# File 'lib/stupidedi/reader/separators.rb', line 61 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.
44 45 46 47 48 49 50 |
# File 'lib/stupidedi/reader/separators.rb', line 44 def merge(other) Separators.new \ other.component || @component, other.repetition || @repetition, other.element || @element, other.segment || @segment end |