class Hippo_eyeDoc::TransactionSets::Component
Attributes
conditions[R]
identified_by[R]
klass[R]
maximum[R]
options[R]
sequence[R]
Public Class Methods
new(options)
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 5 def initialize(options) @identified_by = options.delete(:identified_by) || {} @conditions = options.delete(:parent_context_conditions) || {} @maximum = options.delete(:maximum) || 1 @klass = options.delete(:klass) @sequence = options.delete(:sequence) @options = options end
Public Instance Methods
conditions_match?(instance, segment)
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 86 def conditions_match?(instance, segment) if conditions.empty? true else conditions.all? do |method, expected| Array(expected).include?(instance.instance_eval("self." + method)) end end end
identifier()
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 28 def identifier @klass.identifier end
initialize_component(parent)
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 52 def initialize_component(parent) if repeating? RepeatingComponent.new(self, parent) else populate_component(@klass.new(:parent => parent)) end end
populate_component(component, defaults = nil)
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 32 def populate_component(component, defaults = nil) defaults ||= identified_by defaults.each do |key, value| value = Array(value) if key =~ /(\w+)\.(.+)/ next_component, next_component_value = component.send($1.to_sym), {$2 => value} populate_component(next_component, next_component_value) else next if value.length > 1 component.send((key + '=').to_sym, value.first) end end component end
repeating?()
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 15 def repeating? @maximum > 1 end
segment?()
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 24 def segment? @klass.ancestors.include? Hippo_eyeDoc::Segments::Base end
transaction_set?()
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 19 def transaction_set? @klass.ancestors.include? Hippo_eyeDoc::TransactionSets::Base end
Also aliased as: loop?
valid?(segment)
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 60 def valid?(segment) if klass.ancestors.include? Hippo_eyeDoc::Segments::Base valid_segment?(segment) else valid_entry_segment?(segment) end end
valid_entry_segment?(segment)
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 72 def valid_entry_segment?(segment) if identified_by.empty? initial_segment_id = @klass.components.first.identifier segment.identifier == initial_segment_id else path, value = identified_by.first # TODO: handle arbitrary depth in loop identified_by parsing segment_id, field_name = path.split('.') segment.identifier == segment_id && Array(value).include?(segment.send(field_name)) end end
valid_segment?(segment)
click to toggle source
# File lib/hippo_eyeDoc/transaction_sets/component.rb, line 68 def valid_segment?(segment) segment.identifier == identifier && identified_by.all? {|k, v| Array(v).include?(segment.send(k.to_sym))} end