Class: Stupidedi::Reader::CompositeElementTok

Inherits:
Object
  • Object
show all
Includes:
Inspect
Defined in:
lib/stupidedi/reader/tokens/composite_element_tok.rb

Instance Attribute Summary collapse

Constructors collapse

Instance Method Summary collapse

Methods included from Inspect

#inspect

Constructor Details

#initialize(component_toks, position, remainder) ⇒ CompositeElementTok

Returns a new instance of CompositeElementTok.


18
19
20
21
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 18

def initialize(component_toks, position, remainder)
  @component_toks, @position, @remainder =
    component_toks, position, remainder
end

Instance Attribute Details

#component_toksArray<ComponentElementTok> (readonly)

Returns:


10
11
12
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 10

def component_toks
  @component_toks
end

#positionPosition (readonly)

Returns:


13
14
15
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 13

def position
  @position
end

#remainderPosition (readonly)

Returns:


16
17
18
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 16

def remainder
  @remainder
end

Class Method Details

.build(component_toks, position, remainder) ⇒ CompositeElementTok

Returns:


77
78
79
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 77

def build(component_toks, position, remainder)
  new(component_toks, position, remainder)
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 45

def blank?
  @component_toks.all?(&:blank?)
end

#composite?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 57

def composite?
  true
end

#copy(changes = {}) ⇒ CompositeElementTok

Returns:


24
25
26
27
28
29
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 24

def copy(changes = {})
  CompositeElementTok.new \
    changes.fetch(:component_toks, @component_toks),
    changes.fetch(:position, @position),
    changes.fetch(:remainder, @remainder)
end

#present?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 49

def present?
  not blank?
end

#pretty_print(q)

:nocov:


32
33
34
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 32

def pretty_print(q)
  q.pp(:composite.cons(@component_toks))
end

#repeated

:nocov:


37
38
39
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 37

def repeated
  RepeatedElementTok.new(self.cons, @position)
end

#repeated?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 41

def repeated?
  false
end

#simple?Boolean

Returns:

  • (Boolean)

53
54
55
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 53

def simple?
  false
end

#to_x12(separators)


61
62
63
64
65
66
67
68
69
# File 'lib/stupidedi/reader/tokens/composite_element_tok.rb', line 61

def to_x12(separators)
  if blank?
    ""
  else
    cs  = @component_toks.map{|x| x.to_x12(separators) }
    sep = separators.component || ":"
    cs.join(sep).gsub(/#{Regexp.escape(sep)}+$/, "")
  end
end