Class: ToFactory::Collation
- Inherits:
-
Object
- Object
- ToFactory::Collation
- Defined in:
- lib/to_factory/collation.rb
Class Method Summary collapse
Instance Method Summary collapse
- #detect_collisions!(a, b) ⇒ Object
-
#initialize(a, b) ⇒ Collation
constructor
A new instance of Collation.
- #organize ⇒ Object
- #representations ⇒ Object
Constructor Details
#initialize(a, b) ⇒ Collation
Returns a new instance of Collation.
13 14 15 16 |
# File 'lib/to_factory/collation.rb', line 13 def initialize(a, b) @a = a @b = b end |
Class Method Details
.organize(a, b) ⇒ Object
5 6 7 |
# File 'lib/to_factory/collation.rb', line 5 def self.organize(a,b) new(a, b).organize end |
.representations_from(a, b) ⇒ Object
9 10 11 |
# File 'lib/to_factory/collation.rb', line 9 def self.representations_from(a,b) new(a, b).representations end |
Instance Method Details
#detect_collisions!(a, b) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# 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 ⇒ Object
18 19 20 21 22 23 |
# 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(&:hierarchy_order) o end end |
#representations ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |