Navigation Menu

Skip to content

Commit

Permalink
Use the term "numeric" instead of "number"
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 21, 2015
1 parent f69fbf5 commit 9ea90c0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/droonga/reducer.rb
Expand Up @@ -91,8 +91,8 @@ def recursive_sum(x, y)
return x || y if x.nil? or y.nil?

if x.is_a?(Hash) and y.is_a?(Hash)
if number_hash?(x) and number_hash?(y)
sum_number_hashes(x, y)
if numeric_hash?(x) and numeric_hash?(y)
sum_numeric_hashes(x, y)
else
x.merge(y)
end
Expand Down Expand Up @@ -184,27 +184,27 @@ def unify_by_key!(base_items, unified_items, options={})
end
end

def number_hash?(hash)
def numeric_hash?(hash)
return false unless hash.is_a?(Hash)
hash.values.all? do |value|
case value
when Numeric
true
when Hash
number_hash?(value)
numeric_hash?(value)
else
false
end
end
end

def sum_number_hashes(x, y)
def sum_numeric_hashes(x, y)
sum = {}
(x.keys + y.keys).each do |key|
x_value = x[key]
y_value = y[key]
if number_hash?(x_value) and number_hash?(y_value)
sum[key] = sum_number_hashes(x_value, y_value)
if numeric_hash?(x_value) and numeric_hash?(y_value)
sum[key] = sum_numeric_hashes(x_value, y_value)
else
sum[key] = (x_value || 0) + (y_value || 0)
end
Expand Down

0 comments on commit 9ea90c0

Please sign in to comment.