Class: Eddy::Build::Loop::Repeat

Inherits:
Object
  • Object
show all
Defined in:
lib/eddy/build/loop/repeat.rb

Overview

Generate Ruby code from JSON/YAML EDI definitions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(summary, t_set_id) ⇒ void

Parameters:



18
19
20
21
# File 'lib/eddy/build/loop/repeat.rb', line 18

def initialize(summary, t_set_id)
  self.summary  = summary
  self.t_set_id = t_set_id
end

Instance Attribute Details

#summaryEddy::Summary::Loop

Returns:



10
11
12
# File 'lib/eddy/build/loop/repeat.rb', line 10

def summary
  @summary
end

#t_set_idString

Namespace the Loop is within.

Returns:

  • (String)


13
14
15
# File 'lib/eddy/build/loop/repeat.rb', line 13

def t_set_id
  @t_set_id
end

Instance Method Details

#accessorsString

Returns:

  • (String)


72
73
74
75
76
77
78
79
80
81
# File 'lib/eddy/build/loop/repeat.rb', line 72

def accessors()
  defs = self.summary.components.map do |comp|
    if comp.is_a?(Eddy::Summary::Loop) && comp.repeat_limit > 1
      Eddy::Build::TransactionSetBuilder.loop_accessor(comp, self.t_set_id)
    else
      Eddy::Build::TransactionSetBuilder.segment_accessor(comp.id)
    end
  end
  return defs.join("\n\n")
end

#declarationsString

Returns:

  • (String)


62
63
64
65
66
67
68
69
# File 'lib/eddy/build/loop/repeat.rb', line 62

def declarations()
  self.summary.components.map do |comp|
    case comp
    when Eddy::Summary::Segment then "  @#{comp.id.downcase} = Eddy::Segments::#{comp.id.upcase}.new(store)"
    when Eddy::Summary::Loop    then "  @#{comp.var_name} = Eddy::TransactionSets::#{t_set_id}::Loops::#{comp.id.upcase}::Base.new(store)"
    end
  end.compact.join("\n")
end

#ginny_classGinny::Class

Returns:

  • (Ginny::Class)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/eddy/build/loop/repeat.rb', line 29

def ginny_class()
  return Ginny::Class.create({
    classify_name: false,
    parent: "Eddy::Models::Loop::Repeat",
    name: "Repeat",
    description: "(see Eddy::TransactionSets::#{t_set_id}::Loops::#{self.summary.id}::Base)",
    body: <<~STR.strip,
      # @param store [Eddy::Data::Store]
      # @return [void]
      def initialize(store)
      #{self.declarations()}
        super(
          store,
        #{self.super_call()}
        )
      end

      #{self.accessors()}
    STR
  })
end

#renderString

Returns:

  • (String)


24
25
26
# File 'lib/eddy/build/loop/repeat.rb', line 24

def render()
  return self.ginny_class.render()
end

#super_callString

Returns:

  • (String)


52
53
54
55
56
57
58
59
# File 'lib/eddy/build/loop/repeat.rb', line 52

def super_call()
  return self.summary.components.map do |comp|
    case comp
    when Eddy::Summary::Segment then "  @#{comp.id.downcase},"
    when Eddy::Summary::Loop    then "  @#{comp.var_name},"
    end
  end.compact.join("\n  ")
end