Class: 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
- #copy(changes = {}) ⇒ SegmentTok
-
#initialize(id, element_toks, position, remainder) ⇒ SegmentTok
constructor
A new instance of SegmentTok.
- #present? ⇒ Boolean
- #pretty_print(q) ⇒ Object
- #to_s(separators) ⇒ Object
Methods included from Inspect
Constructor Details
#initialize(id, element_toks, position, remainder) ⇒ SegmentTok
Returns a new instance of SegmentTok.
22 23 24 25 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 22 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)
14 15 16 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 14 def element_toks @element_toks end |
#id ⇒ Symbol (readonly)
11 12 13 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 11 def id @id end |
#position ⇒ Position (readonly)
17 18 19 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 17 def position @position end |
#remainder ⇒ Position (readonly)
20 21 22 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 20 def remainder @remainder end |
Class Method Details
.build(id, element_toks, position, remainder) ⇒ SegmentTok
63 64 65 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 63 def build(id, element_toks, position, remainder) new(id, element_toks, position, remainder) end |
Instance Method Details
#blank? ⇒ Boolean
40 41 42 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 40 def blank? @element_toks.all?(&:blank?) end |
#copy(changes = {}) ⇒ SegmentTok
28 29 30 31 32 33 34 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 28 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
44 45 46 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 44 def present? not blank? end |
#pretty_print(q) ⇒ Object
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_s(separators) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/stupidedi/reader/tokens/segment_tok.rb', line 48 def to_s(separators) if blank? "#{id}#{separators.segment}" else es = @element_toks.map{|x| x.to_s(separators) } id.cons(es).join(separators.element) + separators.segment end end |