class Eddy::Summary::TransactionSet

An outline of all required components for an EDI transaction set implementation.

Attributes

components[RW]

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

functional_group[RW]

A short string used to group related Transaction Sets. @return [String]

id[RW]

A short code identifying the Transaction Set. @return [Integer]

name[RW]

A descriptive name for the Transaction Set. @return [String]

Public Class Methods

create(params = {}) click to toggle source

@param params [Hash] @return [self]

# File lib/eddy/summary/transaction_set.rb, line 26
def self.create(params = {})
  summary = new()
  summary.id = params[:id]
  summary.name = params[:name]
  summary.functional_group = params[:functional_group]
  summary.process_components(params[:components])
  return summary
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/transaction_set.rb, line 37
def self.from_file(path)
  raise Eddy::Errors::Error, "Invalid transaction set definition" unless Eddy::Summary.valid_transaction_set_data?(path)
  data = Eddy::Util.read_json_or_yaml(path)
  return Eddy::Summary::TransactionSet.create(data)
end
new() click to toggle source

@return [void]

# File lib/eddy/summary/transaction_set.rb, line 20
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/transaction_set.rb, line 78
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
doc_comment(header: true) click to toggle source

Generate a description to use as a doc comment for a transaction set.

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

# File lib/eddy/summary/transaction_set.rb, line 64
      def doc_comment(header: true)
        parts = []
        parts << "### Transaction Set Summary:\n" if header
        parts << <<~YARD.strip
          - Id: #{self.id}
          - Name: #{self.name}
          - Functional Group: #{self.functional_group}
        YARD
        return parts.compact.join("\n")
      end
normalized_name() click to toggle source

@return [String]

# File lib/eddy/summary/transaction_set.rb, line 56
def normalized_name
  return "TS#{self.id}"
end
process_components(components) click to toggle source

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

# File lib/eddy/summary/transaction_set.rb, line 45
def process_components(components)
  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
unique_loops() click to toggle source

Return one of each kind of loop in the Transaction Set.

@return [Array<Eddy::Summary::Loop>]

# File lib/eddy/summary/transaction_set.rb, line 91
def unique_loops()
  return self.all_components.select { |c| c.is_a?(Eddy::Summary::Loop) }.uniq(&:id)
end