class Eddy::Summary::Loop

A repeated collection of Segments and/or other Loops. Used in Companion Guides.

Attributes

components[RW]

The components that make up the Loop. @return [Array<Eddy::Summary::Segment, Eddy::Summary::Loop>]

id[RW]

A unique string used to identify the Loop within its Transaction Set. @return [String]

level[RW]

Indicates where the Loop is located in the Transaction Set. @return [String]

notes[RW]

Syntax, Semantic, or Comment notes on a Loop. @return [String]

repeat_limit[RW]

Number of times a particular Loop may be repeated. @return [Integer]

req[RW]

Defines if/how the Loop is required. @return [String]

Public Class Methods

create(params = {}) click to toggle source

@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
from_file(path) click to toggle source

@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
new() click to toggle source

@return [void]

# File lib/eddy/summary/loop.rb, line 26
def initialize()
  self.components = []
end

Public Instance Methods

all_components() click to toggle source

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
build_as_segment?() click to toggle source

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
class_name() click to toggle source

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
doc_comment(header: true) click to toggle source

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
hierarchical?() click to toggle source

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
process_components(components) click to toggle source

@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
var_name() click to toggle source

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