Class: Stupidedi::Values::SegmentVal

Inherits:
AbstractVal show all
Extended by:
Forwardable
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

- (SegmentVal) initialize(children, usage, position)

Returns a new instance of SegmentVal



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

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

Instance Attribute Details

- (Array<AbstractElementVal>) children (readonly)



13
14
15
# File 'lib/stupidedi/values/segment_val.rb', line 13

def children
  @children
end

- (Position) position (readonly)

Returns:

  • (Position)


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

def position
  @position
end

- (SegmentUse) usage (readonly)

Returns:

  • (SegmentUse)


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

def usage
  @usage
end

Instance Method Details

- (Boolean) ==(other)

Returns:

  • (Boolean)


98
99
100
101
102
# File 'lib/stupidedi/values/segment_val.rb', line 98

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

- (SegmentVal) copy(changes = {})

Returns:



27
28
29
30
31
32
# File 'lib/stupidedi/values/segment_val.rb', line 27

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

- (AbstractElementVal) element(m, n = nil, o = nil)

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/stupidedi/values/segment_val.rb', line 60

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

- (Symbol) id

Returns:



40
41
42
# File 'lib/stupidedi/values/segment_val.rb', line 40

def id
  definition.id
end

- (String) inspect

Returns:



93
94
95
# File 'lib/stupidedi/values/segment_val.rb', line 93

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

- (Boolean) leaf?

Returns false

Returns:

  • (Boolean)

    false



45
46
47
# File 'lib/stupidedi/values/segment_val.rb', line 45

def leaf?
  false
end

- pretty_print(q)

This method returns an undefined value.



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

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?

Returns:

  • true



55
56
57
# File 'lib/stupidedi/values/segment_val.rb', line 55

def segment?
  true
end

- (Integer) size

Number of segments in this subtree

Returns:



35
36
37
# File 'lib/stupidedi/values/segment_val.rb', line 35

def size
  1
end

- (Boolean) valid?

Returns:

  • (Boolean)


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

def valid?
  true
end