Class: Geminabox::GemListMerge
- Inherits:
-
Object
- Object
- Geminabox::GemListMerge
- Defined in:
- lib/geminabox/gem_list_merge.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Class Method Summary collapse
Instance Method Summary collapse
- #collection ⇒ Object
- #combine_hashes(other) ⇒ Object
- #ensure_symbols_as_keys(item) ⇒ Object
- #hash ⇒ Object
- #ignore_dependencies ⇒ Object
-
#initialize(list) ⇒ GemListMerge
constructor
A new instance of GemListMerge.
- #merge(other) ⇒ Object
Constructor Details
#initialize(list) ⇒ GemListMerge
Returns a new instance of GemListMerge.
9 10 11 |
# File 'lib/geminabox/gem_list_merge.rb', line 9 def initialize(list) @list = list end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
3 4 5 |
# File 'lib/geminabox/gem_list_merge.rb', line 3 def list @list end |
Class Method Details
.from(*lists) ⇒ Object
5 6 7 |
# File 'lib/geminabox/gem_list_merge.rb', line 5 def self.from(*lists) lists.map{|list| new(list)}.inject(:merge) end |
Instance Method Details
#collection ⇒ Object
29 30 31 |
# File 'lib/geminabox/gem_list_merge.rb', line 29 def collection @collection ||= {} end |
#combine_hashes(other) ⇒ Object
33 34 35 36 37 |
# File 'lib/geminabox/gem_list_merge.rb', line 33 def combine_hashes(other) hash.merge(other.hash) do |key, value, other_value| (value + other_value).uniq{|v| v.values[ignore_dependencies]} end end |
#ensure_symbols_as_keys(item) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/geminabox/gem_list_merge.rb', line 43 def ensure_symbols_as_keys(item) item.keys.each do |key| next if key.kind_of? Symbol item[key.to_sym] = item.delete(key) end end |
#hash ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/geminabox/gem_list_merge.rb', line 19 def hash list.each do |item| ensure_symbols_as_keys(item) name = item[:name].to_sym collection[name] ||= [] collection[name] << item unless collection[name].include?(item) end collection end |
#ignore_dependencies ⇒ Object
39 40 41 |
# File 'lib/geminabox/gem_list_merge.rb', line 39 def ignore_dependencies 0..-2 end |
#merge(other) ⇒ Object
13 14 15 16 17 |
# File 'lib/geminabox/gem_list_merge.rb', line 13 def merge(other) combine_hashes(other).values.flatten.sort do |x, y| x.values[ignore_dependencies] <=> y.values[ignore_dependencies] end end |