class Eddy::Summary::Loop
A repeated collection of Segments
and/or other Loops. Used in Companion Guides.
Attributes
The components that make up the Loop
. @return [Array<Eddy::Summary::Segment, Eddy::Summary::Loop>]
A unique string used to identify the Loop
within its Transaction Set. @return [String]
Indicates where the Loop
is located in the Transaction Set. @return [String]
Syntax, Semantic, or Comment notes on a Loop
. @return [String]
Number of times a particular Loop
may be repeated. @return [Integer]
Defines if/how the Loop
is required. @return [String]
Public Class Methods
@param params [Hash] @return [self]
# 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
@param path [String] Path to a JSON or YAML file containing a valid Loop
definition. @return [self]
# 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
@return [void]
# File lib/eddy/summary/loop.rb, line 26 def initialize() self.components = [] end
Public Instance Methods
Return all components in a single, flattened array.
@return [Array<Eddy::Summary::Segment, Eddy::Summary::Loop>]
# 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
Returns `true` the loop should be treated as a segment when Generating ruby code. (For use in {Eddy::Build})
@return [Boolean]
# 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
Return `id` with the prefixes `l_` or `“hl_”` removed.
@return [String]
# File lib/eddy/summary/loop.rb, line 114 def class_name() return self.id.downcase.gsub(/\Ah?l_/i, "") end
Generate a description to use as a doc comment for a Loop
.
@param header [Boolean] (true) @return [String]
# 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
Returns `true` if the loop is a Hierarchical Loop
. Meant to be used for class or module names.
@return [Boolean]
# File lib/eddy/summary/loop.rb, line 122 def hierarchical?() return self.id =~ /\Ahl_/i end
@param components [Array<Hash>] @return [void]
# 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
Return `id` with `“l_”` slapped on the front if it wasn't already there. Meant to be used for instance variable names.
@return [String]
# 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