class TenderHash::Map
Public Class Methods
new(hash=nil, &block)
click to toggle source
# File lib/tender_hash/map.rb, line 4 def initialize(hash=nil, &block) @old_hash = hash || {} @rules = [] instance_exec(&block) if block_given? end
Public Instance Methods
key(key, options={})
click to toggle source
# File lib/tender_hash/map.rb, line 18 def key(key, options={}) map_key(key, key, options) end
map_key(old, new, options={})
click to toggle source
# File lib/tender_hash/map.rb, line 14 def map_key(old, new, options={}) @rules << Rule.new(old, new, options) end
scope(key, &block)
click to toggle source
# File lib/tender_hash/map.rb, line 22 def scope(key, &block) scope = ScopeRule.new(key, &block) @rules << scope scope.map end
source=(hash)
click to toggle source
# File lib/tender_hash/map.rb, line 10 def source=(hash) @old_hash = hash end
to_h()
click to toggle source
# File lib/tender_hash/map.rb, line 28 def to_h {}.tap do |new_hash| @rules.each do |rule| rule.apply(@old_hash, new_hash) end end end