Update `Utils#pluralized_array_from_hash` and `Utils#value_from_singular_key` per suggestion from @parkr

Switched to using the `#tap` method for more concise code. Also returning the value from
`value_from_singular_key` instead of returning an array wrapped presentation of the value.
This allows for a one-liner in `pluralized_array_from_hash`.
This commit is contained in:
Terry Schmidt 2014-05-20 12:32:59 -05:00
parent 0371b69952
commit c76e41d157
1 changed files with 4 additions and 5 deletions

View File

@ -35,14 +35,13 @@ module Jekyll
#
# Returns an array
def pluralized_array_from_hash(hash, singular_key, plural_key)
array = []
array << value_from_singular_key(hash, singular_key)
array << value_from_plural_key(hash, plural_key) if array.flatten.compact.empty?
array.flatten.compact
[].tap do |array|
array << (value_from_singular_key(hash, singular_key) || value_from_plural_key(hash, plural_key))
end.flatten.compact
end
def value_from_singular_key(hash, key)
[hash[key]] if hash.has_key?(key) || (hash.default_proc && hash[key])
hash[key] if (hash.has_key?(key) || (hash.default_proc && hash[key]))
end
def value_from_plural_key(hash, key)