Class: Stupidedi::Values::SegmentVal

Inherits:
AbstractVal show all
Defined in:
lib/stupidedi/values/segment_val.rb

Overview

See Also:

  • B.1.1.3.4 Data Segment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractVal

#blank?, #characters, #component?, #composite?, #definition, #element?, #empty?, #functional_group?, #interchange?, #invalid?, #loop?, #present?, #repeated?, #separator?, #simple?, #table?, #transaction_set?, #transmission?

Methods included from Color

ansi, #ansi

Constructor Details

#initialize(children, usage, position) ⇒ SegmentVal

Returns a new instance of SegmentVal.



24
25
26
27
# File 'lib/stupidedi/values/segment_val.rb', line 24

def initialize(children, usage, position)
  @children, @usage, @position =
    children, usage, position
end

Instance Attribute Details

#childrenArray<AbstractElementVal> (readonly)

Returns:



16
17
18
# File 'lib/stupidedi/values/segment_val.rb', line 16

def children
  @children
end

#positionPosition (readonly)

Returns:

  • (Position)


22
23
24
# File 'lib/stupidedi/values/segment_val.rb', line 22

def position
  @position
end

#usageSegmentUse (readonly)

Returns:

  • (SegmentUse)


19
20
21
# File 'lib/stupidedi/values/segment_val.rb', line 19

def usage
  @usage
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
105
# File 'lib/stupidedi/values/segment_val.rb', line 101

def ==(other)
  eql?(other) or
   (other.definition == definition and
    other.children   == @children)
end

#copy(changes = {}) ⇒ SegmentVal

Returns:



30
31
32
33
34
35
# File 'lib/stupidedi/values/segment_val.rb', line 30

def copy(changes = {})
  SegmentVal.new \
    changes.fetch(:children, @children),
    changes.fetch(:usage, @usage),
    changes.fetch(:position, @position)
end

#element(m, n = nil, o = nil) ⇒ AbstractElementVal

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/stupidedi/values/segment_val.rb', line 63

def element(m, n = nil, o = nil)
  unless m > 0
    raise ArgumentError,
      "m must be positive"
  end

  unless n.nil?
    @children.at(m - 1).element(n, o)
  else
    @children.at(m - 1)
  end
end

#idSymbol

Returns:

  • (Symbol)


43
44
45
# File 'lib/stupidedi/values/segment_val.rb', line 43

def id
  definition.id
end

#inspectString

Returns:

  • (String)


96
97
98
# File 'lib/stupidedi/values/segment_val.rb', line 96

def inspect
  ansi.segment(ansi.bold(definition.id.to_s))
end

#leaf?Boolean

Returns false.

Returns:

  • (Boolean)

    false



48
49
50
# File 'lib/stupidedi/values/segment_val.rb', line 48

def leaf?
  false
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/stupidedi/values/segment_val.rb', line 77

def pretty_print(q)
  id = definition.try do |d|
    ansi.bold("[#{d.id}: #{d.name}]")
  end

  q.text(ansi.segment("SegmentVal#{id}"))
  q.group(2, "(", ")") do
    q.breakable ""
    @children.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
  end
end

#segment?Object

Returns:

  • true



58
59
60
# File 'lib/stupidedi/values/segment_val.rb', line 58

def segment?
  true
end

#sizeInteger

Number of segments in this subtree

Returns:

  • (Integer)


38
39
40
# File 'lib/stupidedi/values/segment_val.rb', line 38

def size
  1
end

#valid?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/stupidedi/values/segment_val.rb', line 52

def valid?
  true
end