class HashMerge
Public Class Methods
new(origin, custom)
click to toggle source
# File lib/hashMerge.rb, line 2 def initialize(origin, custom) @dough = origin @materials = custom end
Public Instance Methods
baked!()
click to toggle source
# File lib/hashMerge.rb, line 7 def baked! merge @dough, @materials end
merge(dough, materials)
click to toggle source
# File lib/hashMerge.rb, line 11 def merge(dough, materials) mergeForHash(dough, materials) if dough.respond_to? :merge! dough + materials if not dough.respond_to? :merge! end
Protected Instance Methods
blend(dough, part)
click to toggle source
# File lib/hashMerge.rb, line 42 def blend(dough, part) flag = true dough.each do |hash| if hash.keys == part.keys flag = false next recursiveMerge(hash, part) end end dough << part if flag end
categorized(dough, material)
click to toggle source
# File lib/hashMerge.rb, line 25 def categorized(dough, material) hash_dough, string_dough = split dough material_hash, material_string = split material hash = combineHash(hash_dough, material_hash) summary = string_dough + material_string + hash end
combine(dough, materials)
click to toggle source
# File lib/hashMerge.rb, line 37 def combine(dough, materials) materials.each { |part| blend dough, part } dough end
combineHash(*parts)
click to toggle source
# File lib/hashMerge.rb, line 33 def combineHash(*parts) (combine parts[0], parts[1]).to_set end
mergeForHash(dough, material)
click to toggle source
# File lib/hashMerge.rb, line 18 def mergeForHash(dough, material) dough.merge! (material) do |key, dough, material| dough, material = setify dough, material next categorized dough, material end end
recursiveMerge(origin, custom)
click to toggle source
# File lib/hashMerge.rb, line 53 def recursiveMerge(origin, custom) origin.merge! custom do |key, origin, custom| merge origin, custom end end
setify(*list)
click to toggle source
# File lib/hashMerge.rb, line 59 def setify(*list) list.map do |obj| obj = [obj].to_set if not obj.is_a? Set obj end end
split(set)
click to toggle source
# File lib/hashMerge.rb, line 66 def split(set) hash = set.to_a.keep_if { |value| value.is_a? Hash } string = set - hash return hash, string.to_set end