class ToFactory::Collation
Public Class Methods
new(a, b)
click to toggle source
# File lib/to_factory/collation.rb, line 13 def initialize(a, b) @a = a @b = b end
organize(a,b)
click to toggle source
# File lib/to_factory/collation.rb, line 5 def self.organize(a,b) new(a, b).organize end
representations_from(a,b)
click to toggle source
# File lib/to_factory/collation.rb, line 9 def self.representations_from(a,b) new(a, b).representations end
Public Instance Methods
detect_collisions!(a,b)
click to toggle source
# File lib/to_factory/collation.rb, line 39 def detect_collisions!(a,b) collisions = [] a.each do |x| b.each do |y| collisions << x.name if x.name == y.name end end raise_already_exists!(collisions) if collisions.any? end
organize()
click to toggle source
# File lib/to_factory/collation.rb, line 18 def organize representations.group_by{|i| i.klass.name.underscore}.inject({}) do |o, (klass_name,r)| o[klass_name] = r.sort_by{|r| [r.hierarchy_order, r.name]} o end end
representations()
click to toggle source
# File lib/to_factory/collation.rb, line 25 def representations detect_collisions!(@a,@b) inference = KlassInference.new(merged) merged.each do |r| klass, order = inference.infer(r.name) r.klass = klass r.hierarchy_order = order end merged end
Private Instance Methods
merged()
click to toggle source
# File lib/to_factory/collation.rb, line 52 def merged @merged ||= @a + @b end
raise_already_exists!(keys)
click to toggle source
# File lib/to_factory/collation.rb, line 56 def raise_already_exists!(keys) raise ToFactory::AlreadyExists.new "an item for each of the following keys #{keys.inspect} already exists" end