Class: Stupidedi::Schema::TransactionSetDef

Inherits:
AbstractDef
  • Object
show all
Includes:
Inspect
Defined in:
lib/stupidedi/schema/transaction_set_def.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inspect

#inspect

Methods inherited from AbstractDef

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

Constructor Details

#initialize(functional_group, id, name, table_defs) ⇒ TransactionSetDef

Returns a new instance of TransactionSetDef.


21
22
23
24
25
26
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 21

def initialize(functional_group, id, name, table_defs)
  @functional_group, @id, @name, @table_defs =
    functional_group, id, name, table_defs

  @table_defs = table_defs.map{|x| x.copy(:parent => self) }
end

Instance Attribute Details

#functional_groupString (readonly)

Returns:

  • (String)

16
17
18
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 16

def functional_group
  @functional_group
end

#idString (readonly)

Returns:

  • (String)

10
11
12
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 10

def id
  @id
end

#nameString (readonly)

Returns:

  • (String)

13
14
15
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 13

def name
  @name
end

#table_defsArray<TableDef> (readonly)

Returns:


19
20
21
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 19

def table_defs
  @table_defs
end

Class Method Details

.build(functional_group, id, name, *table_defs) ⇒ TransactionSetDef

Returns:


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 93

def build(functional_group, id, name, *table_defs)
  table_defs.each.with_index do |t, k|
    unless t.table?
      if t.respond_to?(:pretty_inspect)
        raise Exceptions::InvalidSchemaError,
          "argument #{k+4} is not a TableDef: #{t.pretty_inspect}"
      else
        raise Exceptions::InvalidSchemaError,
          "argument #{k+4} is not a TableDef: #{t.inspect}"
      end
    end

    # next unless t.repeatable?

    # [t.header_segment_uses, t.loop_defs, t.trailer_segment_uses].each do |s|
    #   opt, req = s.split_until(&:optional?)
    #   prefix   = opt.concat(req.take(1))

    #   if x = prefix.find(&:repeatable?)
    #     raise Exceptions::InvalidSchemaError,
    #       %Q("#{x.id}" is an entry point into "#{t.id}", and both are marked
    #       repeatable).join
    #   end

    #   break if req.present?
    # end
  end

  new(functional_group, id, name, table_defs)
end

Instance Method Details

#childrenArray<TableDef>

Returns:


62
63
64
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 62

def children
  @table_defs
end

#code_listsAbstractSet<CodeList>

Returns:


71
72
73
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 71

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

#copy(changes = {})


28
29
30
31
32
33
34
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 28

def copy(changes = {})
  TransactionSetDef.new \
    changes.fetch(:functional_group, @functional_group),
    changes.fetch(:id, @id),
    changes.fetch(:name, @name),
    changes.fetch(:table_defs, @table_defs)
end

#descriptorString

Returns:

  • (String)

37
38
39
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 37

def descriptor
  "transaction set #{functional_group}#{id} #{name}"
end

#emptyValues::TransactionSetVal


42
43
44
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 42

def empty
  Values::TransactionSetVal.new(self, [])
end

#entry_segment_useSegmentUse

Returns:


47
48
49
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 47

def entry_segment_use
  @table_defs.head.header_segment_uses.head
end

#first_segment_useSegmentUse

Returns:


52
53
54
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 52

def first_segment_use
  @table_defs.head.header_segment_uses.head
end

#last_segment_useSegmentUse

Returns:


57
58
59
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 57

def last_segment_use
  @table_defs.last.trailer_segment_uses.last
end

#pretty_print(q)

This method returns an undefined value.


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

def pretty_print(q)
  q.text("TransactionSetDef[#{@functional_group}#{@id}]")
  q.group(2, "(", ")") do
    q.breakable ""
    @table_defs.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
  end
end

#transaction?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'lib/stupidedi/schema/transaction_set_def.rb', line 66

def transaction?
  true
end