class ParsableHash::Parser
Public Class Methods
new(hash, strategy)
click to toggle source
# File lib/parsable_hash/parser.rb, line 3 def initialize(hash, strategy) @hash = hash @strategy = HashStrategy.new(strategy, @hash) end
Public Instance Methods
call()
click to toggle source
# File lib/parsable_hash/parser.rb, line 8 def call deep_parse(@hash, @strategy.hash) end
Private Instance Methods
deep_parse(hash, strategy)
click to toggle source
# File lib/parsable_hash/parser.rb, line 13 def deep_parse(hash, strategy) hash.merge(strategy) do |key, val, str| if val.is_a?(Hash) && str.is_a?(Hash) deep_parse(val, str) else parse_with_strategy(val, str) end end end
parse_with_strategy(value, strategy)
click to toggle source
# File lib/parsable_hash/parser.rb, line 23 def parse_with_strategy(value, strategy) strategy.call(value) end