class Alder::Transform

Public Class Methods

new(rules) click to toggle source
# File lib/alder/transform.rb, line 6
def initialize(rules)
  @rules = rules
end

Public Instance Methods

apply(hash) click to toggle source
# File lib/alder/transform.rb, line 10
def apply(hash)
  transform(hash.deep_dup)
end
Also aliased as: call
call(hash)
Alias for: apply

Private Instance Methods

apply_rules(rules, hash) click to toggle source
# File lib/alder/transform.rb, line 35
def apply_rules(rules, hash)
  rules.each_with_object(hash) do |rule, result|
    rule.apply(result)
  end
end
descend_into(hash) click to toggle source
# File lib/alder/transform.rb, line 23
def descend_into(hash)
  hash.each_with_object(hash) do |(key, value), result|
    case
    when value.is_a?(Hash)
      result[key] = transform(value)
    when value.is_a?(Array)
      result[key] = value.map { |v| transform(v) }
    end
    result
  end
end
transform(hash) click to toggle source
# File lib/alder/transform.rb, line 18
def transform(hash)
  descend_into(hash)
  apply_rules(@rules, hash)
end