class Eddy::Summary::Segment

A collection of Data Elements. Used in Companion Guides to define a Transaction Set.

Attributes

element_count[RW]

Number of Data Elements included in the Segment. @return [Integer]

elements[RW]

Number of Data Elements included in the Segment. @return [Array<Eddy::Summary::Element>]

id[RW]

Short string identifying the Segment. @return [String]

level[RW]

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

max_use[RW]

Number of times a particular Segment may be repeated at its location in the Transaction Set. @return [Integer]

name[RW]

Full name of the Segment. @return [String]

notes[RW]

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

pos[RW]

Indicates the order in which Segments should appear in their Level of the Transaction Set. @return [String]

purpose[RW]

Documents the purpose of a Segment. @return [String]

req[RW]

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

usage[RW]

Indicates whether or not the Segment must be used; Somewhat redundant due to `Req`. @return [String]

Public Class Methods

create(params = {}) click to toggle source

@param params [Hash] @return [self]

# File lib/eddy/summary/segment.rb, line 47
def self.create(params = {})
  s = new()
  s.pos           = params[:pos]
  s.id            = params[:id]
  s.name          = params[:name]
  s.purpose       = params[:purpose]
  s.max_use       = params[:max_use]
  s.notes         = params[:notes]
  s.usage         = params[:usage]
  s.element_count = params[:element_count]
  s.req           = params[:req]
  s.level         = params[:level]
  s.process_elements(params[:elements])
  return s
end
default_for_id(id) click to toggle source

@param id [String] @return [self]

# File lib/eddy/summary/segment.rb, line 73
def self.default_for_id(id)
  id.downcase!
  if ["ge", "gs", "iea", "isa", "se", "st"].include?(id)
    path = File.join(Eddy::Util.data_dir, "segments", "envelope", "#{id}.segment.yml")
    return self.from_file(path)
  end
  path = File.join(Eddy::Util.data_dir, "segments", "#{id}.segment.yml")
  raise Eddy::Errors::Error, "No segment found with id #{id}" unless File.file?(path)
  return self.from_file(path)
end
from_file(path) click to toggle source

@param path [String] Path to a JSON or YAML file containing a valid Segment definition. @return [self]

# File lib/eddy/summary/segment.rb, line 65
def self.from_file(path)
  raise Eddy::Errors::Error, "Invalid segment definition" unless Eddy::Summary.valid_segment_data?(path)
  data = Eddy::Util.read_json_or_yaml(path)
  return Eddy::Summary::Segment.create(data)
end
new() click to toggle source

@return [void]

# File lib/eddy/summary/segment.rb, line 41
def initialize()
  self.elements = []
end

Public Instance Methods

build_as_segment?() click to toggle source

Helper function to simplify conditional logic in {Eddy::Build}.

See `Eddy::Summary::Loop#treat_as_segment?`

@return [Boolean] (true) Always returns true.

# File lib/eddy/summary/segment.rb, line 119
def build_as_segment?()
  return true
end
doc_comment(header: true) click to toggle source

Generate a description to use as a doc comment for a segment.

@param header [Boolean] (true) @return [String]

# File lib/eddy/summary/segment.rb, line 103
      def doc_comment(header: true)
        parts = []
        parts << "### Segment Summary:\n" if header
        parts << <<~YARD.strip
          - Id: #{self.id}
          - Name: #{self.name}
          - Purpose: #{self.purpose}
        YARD
        return parts.compact.join("\n")
      end
process_elements(elements) click to toggle source

TODO: Only use defaults if not enough info is provided. TODO: Define *enough info*.

@param elements [Array<Hash>] @return [void]

# File lib/eddy/summary/segment.rb, line 89
def process_elements(elements)
  return if elements.nil?
  elements.each do |el|
    default_el = Eddy::Summary::Element.default_for_id(el[:id])
    default_el.ref = el[:ref]
    default_el.req = el[:req] || nil
    self.elements << default_el
  end
end