class Eddy::Summary::TransactionSet
An outline of all required components for an EDI transaction set implementation.
Attributes
The components that make up the Transaction Set. @return [Array<Eddy::Summary::Segment, Eddy::Summary::Loop>]
A short string used to group related Transaction Sets. @return [String]
A short code identifying the Transaction Set. @return [Integer]
A descriptive name for the Transaction Set. @return [String]
Public Class Methods
@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
@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
@return [void]
# File lib/eddy/summary/transaction_set.rb, line 20 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/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
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
@return [String]
# File lib/eddy/summary/transaction_set.rb, line 56 def normalized_name return "TS#{self.id}" end
@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
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