Class: Stupidedi::Schema::SegmentDef

Inherits:
AbstractDef show all
Includes:
Inspect
Defined in:
lib/stupidedi/schema/segment_def.rb

Overview

See Also:

  • B.1.1.3.4 Data Segment

Instance Attribute Summary collapse

Constructors collapse

Instance Method Summary collapse

Methods included from Inspect

#inspect

Methods inherited from AbstractDef

#component?, #composite?, #definition?, #element?, #functional_group?, #interchange?, #loop?, #repeated?, #simple?, #table?, #transaction_set?, #usage?

Constructor Details

#initialize(id, name, purpose, element_uses, syntax_notes, parent) ⇒ SegmentDef

Returns a new instance of SegmentDef.



28
29
30
31
32
33
34
35
36
37
# File 'lib/stupidedi/schema/segment_def.rb', line 28

def initialize(id, name, purpose, element_uses, syntax_notes, parent)
  @id, @name, @purpose, @element_uses, @syntax_notes, @parent =
    id, name, purpose, element_uses, syntax_notes, parent

  # Delay re-parenting until the entire definition tree has a root
  # to prevent unnecessarily copying objects
  unless parent.nil?
    @element_uses = @element_uses.map{|x| x.copy(:parent => self) }
  end
end

Instance Attribute Details

#element_usesArray<SimpleElementUse, CompositeElementUse> (readonly)



20
21
22
# File 'lib/stupidedi/schema/segment_def.rb', line 20

def element_uses
  @element_uses
end

#idSymbol (readonly)

Returns:



11
12
13
# File 'lib/stupidedi/schema/segment_def.rb', line 11

def id
  @id
end

#nameString (readonly)

Returns:



14
15
16
# File 'lib/stupidedi/schema/segment_def.rb', line 14

def name
  @name
end

#parentSegmentUse (readonly)

Returns:



26
27
28
# File 'lib/stupidedi/schema/segment_def.rb', line 26

def parent
  @parent
end

#purposeString (readonly)

Returns:



17
18
19
# File 'lib/stupidedi/schema/segment_def.rb', line 17

def purpose
  @purpose
end

#syntax_notesArray<SyntaxNote> (readonly)

Returns:



23
24
25
# File 'lib/stupidedi/schema/segment_def.rb', line 23

def syntax_notes
  @syntax_notes
end

Class Method Details

.build(id, name, purpose, *args) ⇒ SegmentDef

Returns:



95
96
97
98
99
100
101
# File 'lib/stupidedi/schema/segment_def.rb', line 95

def build(id, name, purpose, *args)
  element_uses = args.take_while{|x| x.is_a?(AbstractElementUse) }
  syntax_notes = args.drop(element_uses.length)

  # @todo: Validate SyntaxNotes
  new(id, name, purpose, element_uses, syntax_notes, nil)
end

Instance Method Details

#code_listsAbstractSet<CodeList>

Returns:



69
70
71
# File 'lib/stupidedi/schema/segment_def.rb', line 69

def code_lists
  @element_uses.map(&:code_lists).inject(&:|)
end

#copy(changes = {}) ⇒ SegmentDef

Returns:



40
41
42
43
44
45
46
47
48
# File 'lib/stupidedi/schema/segment_def.rb', line 40

def copy(changes = {})
  SegmentDef.new \
    changes.fetch(:id, @id),
    changes.fetch(:name, @name),
    changes.fetch(:purpose, @purpose),
    changes.fetch(:element_uses, @element_uses),
    changes.fetch(:syntax_notes, @syntax_notes),
    changes.fetch(:parent, @parent)
end

#empty(usage) ⇒ Values::SegmentVal

Returns:



56
57
58
# File 'lib/stupidedi/schema/segment_def.rb', line 56

def empty(usage)
  Values::SegmentVal.new([], usage)
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/stupidedi/schema/segment_def.rb', line 74

def pretty_print(q)
  q.text "SegmentDef[#{@id}]"

  q.group(2, "(", ")") do
    q.breakable ""
    @element_uses.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
  end
end

#segment?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/stupidedi/schema/segment_def.rb', line 64

def segment?
  true
end

#use(position, requirement, repeat_count) ⇒ SegmentUse

Returns:



51
52
53
# File 'lib/stupidedi/schema/segment_def.rb', line 51

def use(position, requirement, repeat_count)
  SegmentUse.new(self, position, requirement, repeat_count, nil)
end

#value(element_vals, usage, position) ⇒ Object



60
61
62
# File 'lib/stupidedi/schema/segment_def.rb', line 60

def value(element_vals, usage, position)
  Values::SegmentVal.new(element_vals, usage, position)
end