Class: Eddy::Summary::Loop
- Inherits:
-
Object
- Object
- Eddy::Summary::Loop
- Defined in:
- lib/eddy/summary/loop.rb
Overview
A repeated collection of Segments and/or other Loops. Used in Companion Guides.
Instance Attribute Summary collapse
-
#components ⇒ Array<Eddy::Summary::Segment, Eddy::Summary::Loop>
The components that make up the Loop.
-
#id ⇒ String
A unique string used to identify the Loop within its Transaction Set.
-
#level ⇒ String
Indicates where the Loop is located in the Transaction Set.
-
#notes ⇒ String
Syntax, Semantic, or Comment notes on a Loop.
-
#repeat_limit ⇒ Integer
Number of times a particular Loop may be repeated.
-
#req ⇒ String
Defines if/how the Loop is required.
Class Method Summary collapse
Instance Method Summary collapse
-
#all_components ⇒ Array<Eddy::Summary::Segment, Eddy::Summary::Loop>
Return all components in a single, flattened array.
-
#build_as_segment? ⇒ Boolean
Returns
true
the loop should be treated as a segment when Generating ruby code. -
#class_name ⇒ String
Return
id
with the prefixes"l_"
or `"hl_" removed. -
#doc_comment(header: true) ⇒ String
Generate a description to use as a doc comment for a Loop.
-
#hierarchical? ⇒ Boolean
Returns
true
if the loop is a Hierarchical Loop. - #initialize ⇒ void constructor
- #process_components(components) ⇒ void
-
#var_name ⇒ String
Return
id
with"l_"
slapped on the front if it wasn't already there.
Constructor Details
#initialize ⇒ void
26 27 28 |
# File 'lib/eddy/summary/loop.rb', line 26 def initialize() self.components = [] end |
Instance Attribute Details
#components ⇒ Array<Eddy::Summary::Segment, Eddy::Summary::Loop>
The components that make up the Loop.
23 24 25 |
# File 'lib/eddy/summary/loop.rb', line 23 def components @components end |
#id ⇒ String
A unique string used to identify the Loop within its Transaction Set.
8 9 10 |
# File 'lib/eddy/summary/loop.rb', line 8 def id @id end |
#level ⇒ String
Indicates where the Loop is located in the Transaction Set.
17 18 19 |
# File 'lib/eddy/summary/loop.rb', line 17 def level @level end |
#notes ⇒ String
Syntax, Semantic, or Comment notes on a Loop.
14 15 16 |
# File 'lib/eddy/summary/loop.rb', line 14 def notes @notes end |
#repeat_limit ⇒ Integer
Number of times a particular Loop may be repeated.
11 12 13 |
# File 'lib/eddy/summary/loop.rb', line 11 def repeat_limit @repeat_limit end |
#req ⇒ String
Defines if/how the Loop is required.
20 21 22 |
# File 'lib/eddy/summary/loop.rb', line 20 def req @req end |
Class Method Details
.create(params = {}) ⇒ self
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/eddy/summary/loop.rb', line 32 def self.create(params = {}) l = new() l.id = params[:loop_id] l.repeat_limit = params[:repeat] l.notes = params[:notes] l.level = params[:level] l.req = params[:req] l.process_components(params[:components]) return l end |
.from_file(path) ⇒ self
45 46 47 48 49 |
# File 'lib/eddy/summary/loop.rb', line 45 def self.from_file(path) raise Eddy::Errors::Error, "Invalid segment definition" unless Eddy::Summary.valid_loop_data?(path) data = Eddy::Util.read_json_or_yaml(path) return self.create(data) end |
Instance Method Details
#all_components ⇒ Array<Eddy::Summary::Segment, Eddy::Summary::Loop>
Return all components in a single, flattened array.
89 90 91 92 93 94 95 96 97 |
# File 'lib/eddy/summary/loop.rb', line 89 def all_components() return self.components.map do |comp| case comp when Eddy::Summary::Loop then [comp, comp.all_components()] when Eddy::Summary::Segment then comp else raise Eddy::Errors::Error end end.flatten end |
#build_as_segment? ⇒ Boolean
Returns true
the loop should be treated as a segment when Generating ruby code.
(For use in Build)
130 131 132 133 134 |
# File 'lib/eddy/summary/loop.rb', line 130 def build_as_segment?() return false if self.hierarchical? return false if self.repeat_limit > 1 return true end |
#class_name ⇒ String
Return id
with the prefixes "l_"
or `"hl_" removed.
114 115 116 |
# File 'lib/eddy/summary/loop.rb', line 114 def class_name() return self.id.downcase.gsub(/\Ah?l_/i, "") end |
#doc_comment(header: true) ⇒ String
Generate a description to use as a doc comment for a Loop.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/eddy/summary/loop.rb', line 68 def doc_comment(header: true) comps = "" self.components.each do |comp| case comp when Eddy::Summary::Segment then comps << " - #{comp.id.upcase}\n" when Eddy::Summary::Loop then comps << " - #{comp.id.upcase} (loop)\n" end end parts = [] parts << "### Loop Summary:\n" if header parts << <<~YARD.strip - Repeat: #{self.repeat_limit} - Components: #{comps} YARD return parts.compact.join("\n") end |
#hierarchical? ⇒ Boolean
Returns true
if the loop is a Hierarchical Loop.
Meant to be used for class or module names.
122 123 124 |
# File 'lib/eddy/summary/loop.rb', line 122 def hierarchical?() return self.id =~ /\Ahl_/i end |
#process_components(components) ⇒ void
This method returns an undefined value.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/eddy/summary/loop.rb', line 53 def process_components(components) return if components.nil? components.each do |comp| if comp.key?(:loop_id) self.components << Eddy::Summary::Loop.create(comp) else self.components << Eddy::Summary::Segment.create(comp) end end end |
#var_name ⇒ String
Return id
with "l_"
slapped on the front if it wasn't already there.
Meant to be used for instance variable names.
103 104 105 106 107 108 109 |
# File 'lib/eddy/summary/loop.rb', line 103 def var_name() if self.id.start_with?(/\Ah?l_/i) return self.id.downcase else return "l_#{self.id.downcase}" end end |