Module: Stupidedi::Guides::FortyTen::GuideBuilder

Defined in:
lib/stupidedi/guides/004010/guide_builder.rb

Overview

GuideBuilder is a simple DSL for construction an implementation guide.

Element Constraints collapse

Definition Constructors collapse

Class Method Summary collapse

Class Method Details

.build(transaction_set_def, *table_defs) ⇒ Schema::TransactionSetDef



17
18
19
# File 'lib/stupidedi/guides/004010/guide_builder.rb', line 17

def build(transaction_set_def, *table_defs)
  transaction_set_def.copy(:table_defs => table_defs)
end

.Element(requirement, name, *constraints) ⇒ Object

Parameters:



47
48
49
# File 'lib/stupidedi/guides/004010/guide_builder.rb', line 47

def Element(requirement, name, *constraints)
  [:Element, requirement, name, constraints]
end

.MaxLength(n) ⇒ Object

Parameters:

  • n (Integer)


30
31
32
# File 'lib/stupidedi/guides/004010/guide_builder.rb', line 30

def MaxLength(n)
  [:MaxLength, n]
end

.MaxPrecision(n) ⇒ Object

Parameters:

  • n (Integer)


35
36
37
# File 'lib/stupidedi/guides/004010/guide_builder.rb', line 35

def MaxPrecision(n)
  [:MaxPrecision, n]
end

.Segment(position, segment_def, name, requirement, repeat_count, *elements) ⇒ SegmentUse

Returns:

  • (SegmentUse)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
# File 'lib/stupidedi/guides/004010/guide_builder.rb', line 52

def Segment(position, segment_def, name, requirement, repeat_count, *elements)
  unless elements.length == segment_def.element_uses.length
    raise Exceptions::InvalidSchemaError,
      "segment #{segment_def.id} has #{segment_def.element_uses.length}" +
      " elements but #{elements.length} arguments were specified"
  end

  element_index = "00"
  element_uses  = elements.zip(segment_def.element_uses).map do |e, u|
    e_tag, e_requirement, e_name, e_arguments = e
    # element_index.succ!
    element_index = element_index.succ
    unless e_tag == :Element
      raise Exceptions::InvalidSchemaError,
        "given argument for #{segment_def.id}#{element_index} must be Element(...)"
    end

    if u.composite?
      e_repeat_count, e_arguments = e_arguments.partition{|x| x.is_a?(Schema::RepeatCount) }

      changes = Hash.new
      changes[:requirement] = e_requirement

      if e_repeat_count.length == 1
        changes[:repeat_count] = e_repeat_count.head
      elsif e_repeat_count.length > 1
        raise Exceptions::InvalidSchemaError,
          "more than one RepeatCount was specified"
      end

      unless e_requirement.forbidden?
        unless e_arguments.length == u.definition.component_uses.length
          raise Exceptions::InvalidSchemaError,
            "composite element #{u.definition.id} at #{segment_def.id}" +
            "#{element_index} has #{u.definition.component_uses.length}" +
            " component elements but #{e_arguments.length} were given"
        end

        # ComponentElementUses
        component_index = "00"
        component_uses  = e_arguments.zip(u.definition.component_uses).map do |e, c|
          c_tag, c_requirement, c_name, c_arguments = e
          # component_index.succ!
          component_index = component_index.succ

          unless c_tag == :Element
            raise Exceptions::InvalidSchemaError,
              "given argument for #{segment_def.id}#{element_index}" +
              "-#{component_index} must be Element(...)"
          end

          mod_element(c, c_requirement, c_name, c_arguments)
        end

        changes[:definition] = u.definition.copy(:name           => e_name,
                                                 :component_uses => component_uses)
      else
        changes[:definition] = u.definition.copy(:name => e_name)
      end

      u.copy(changes)
    else
      mod_element(u, e_requirement, e_name, e_arguments)
    end
  end

  segment_def.copy(:name => name).
    copy(:element_uses => element_uses).
    use(position, requirement, repeat_count)
end

.Values(*values) ⇒ Object

Parameters:

  • values (String, ...)


25
26
27
# File 'lib/stupidedi/guides/004010/guide_builder.rb', line 25

def Values(*values)
  [:Values, values]
end