Class: Stupidedi::Reader::SegmentTok
- Inherits:
-
Object
- Object
- Stupidedi::Reader::SegmentTok
- Includes:
- Inspect
- Defined in:
- lib/stupidedi/reader/tokens/segment_tok.rb
Instance Attribute Summary collapse
- #element_toks ⇒ Array<CompositeElementTok, SimpleElementTok> readonly
- #id ⇒ Symbol readonly
- #position ⇒ Position readonly
- #remainder ⇒ Position readonly
Constructors collapse
Instance Method Summary collapse
-
#blank? ⇒ Boolean
:nocov:.
- #copy(changes = {}) ⇒ SegmentTok
-
#initialize(id, element_toks, position, remainder) ⇒ SegmentTok
constructor
A new instance of SegmentTok.
- #present? ⇒ Boolean
-
#pretty_print(q)
:nocov:.
- #to_x12(separators)
Methods included from Inspect
Constructor Details
#initialize(id, element_toks, position, remainder) ⇒ SegmentTok
Returns a new instance of SegmentTok.
21 22 23 24 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 21 def initialize(id, element_toks, position, remainder) @id, @element_toks, @position, @remainder = id, element_toks, position, remainder end |
Instance Attribute Details
#element_toks ⇒ Array<CompositeElementTok, SimpleElementTok> (readonly)
13 14 15 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 13 def element_toks @element_toks end |
#id ⇒ Symbol (readonly)
10 11 12 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 10 def id @id end |
#position ⇒ Position (readonly)
16 17 18 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 16 def position @position end |
#remainder ⇒ Position (readonly)
19 20 21 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 19 def remainder @remainder end |
Class Method Details
.build(id, element_toks, position, remainder) ⇒ SegmentTok
66 67 68 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 66 def build(id, element_toks, position, remainder) new(id, element_toks, position, remainder) end |
Instance Method Details
#blank? ⇒ Boolean
:nocov:
41 42 43 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 41 def blank? @element_toks.all?(&:blank?) end |
#copy(changes = {}) ⇒ SegmentTok
27 28 29 30 31 32 33 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 27 def copy(changes = {}) SegmentTok.new \ changes.fetch(:id, @id), changes.fetch(:element_toks, @element_toks), changes.fetch(:position, @position), changes.fetch(:remainder, @remainder) end |
#present? ⇒ Boolean
45 46 47 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 45 def present? not blank? end |
#pretty_print(q)
:nocov:
36 37 38 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 36 def pretty_print(q) q.pp(:segment.cons(@id.cons(@element_toks))) end |
#to_x12(separators)
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 49 def to_x12(separators) if blank? "#{id}#{separators.segment}" else es = @element_toks.map{|x| x.to_x12(separators) } sep = separators.element || "*" eos = separators.segment || "~" id.cons(es).join(sep).gsub(/#{Regexp.escape(sep)}+$/, "") + eos.strip end end |