Sha256: 376ead6134ced6e09317abe8eaf7199b6d115a0ad3806d87b7e90bfdeca96c76
Contents?: true
Size: 616 Bytes
Versions: 2
Compression:
Stored size: 616 Bytes
Contents
module Crosscounter module Expansion extend self def expand(keywords, expansions) keywords.inject({}) do |hash, keyword| hash[keyword] = resolved(expansions, keyword) hash end end def replace(enumerable, replacements) enumerable.map do |object| replacements.inject({}) do |hash, replacement| hash[replacement.first] = replacement.last.call(object) hash end end end def resolved(expansions, keyword) value = expansions.fetch(keyword) value.respond_to?(:call) ? value.call : value end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
crosscounter-0.5.0 | lib/crosscounter/expansion.rb |
crosscounter-0.4.0 | lib/crosscounter/expansion.rb |