class StackerBee::Rash

Public Class Methods

new(hash = {}) click to toggle source
# File lib/stacker_bee/rash.rb, line 15
def initialize(hash = {})
  @hash = {}
  hash.each_pair do |key, value|
    @hash[convert_key(key)] = convert_value(value)
  end
  @hash.freeze
end

Protected Class Methods

deep_dup(hash) click to toggle source
# File lib/stacker_bee/rash.rb, line 72
def self.deep_dup(hash)
  hash.dup.tap do |duplicate|
    duplicate.each_pair do |key, value|
      duplicate[key] = deep_dup(value) if value.is_a?(Hash)
    end
  end
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method
# File lib/stacker_bee/rash.rb, line 23
def ==(other)
  case other
  when Rash
    super || @hash == other.to_hash
  when Hash
    self == Rash.new(other)
  else
    super
  end
end
[](key) click to toggle source
# File lib/stacker_bee/rash.rb, line 50
def [](key)
  @hash[convert_key(key)]
end
fetch(key, *args, &block) click to toggle source
# File lib/stacker_bee/rash.rb, line 46
def fetch(key, *args, &block)
  @hash.fetch(convert_key(key), *args, &block)
end
has_key?(key)
Alias for: key?
include?(key)
Alias for: key?
inspect() click to toggle source
# File lib/stacker_bee/rash.rb, line 65
def inspect
  "#<#{self.class} #{@hash}>"
end
Also aliased as: to_s
key?(key) click to toggle source
# File lib/stacker_bee/rash.rb, line 54
def key?(key)
  @hash.key?(convert_key(key))
end
Also aliased as: include?, has_key?, member?
member?(key)
Alias for: key?
reject(*args, &block) click to toggle source
# File lib/stacker_bee/rash.rb, line 38
def reject(*args, &block)
  Rash.new(@hash.reject(*args, &block))
end
select(*args, &block) click to toggle source
# File lib/stacker_bee/rash.rb, line 34
def select(*args, &block)
  Rash.new(@hash.select(*args, &block))
end
to_hash() click to toggle source
# File lib/stacker_bee/rash.rb, line 61
def to_hash
  self.class.deep_dup(@hash)
end
to_s()
Alias for: inspect
values_at(*keys) click to toggle source
# File lib/stacker_bee/rash.rb, line 42
def values_at(*keys)
  @hash.values_at(*keys.map { |key| convert_key(key) })
end

Protected Instance Methods

convert_key(key) click to toggle source
# File lib/stacker_bee/rash.rb, line 80
def convert_key(key)
  key.is_a?(Numeric) ? key : uncase(key)
end
convert_value(value) click to toggle source
# File lib/stacker_bee/rash.rb, line 84
def convert_value(value)
  case value
  when Hash
    Rash.new(value)
  when Array
    value.map { |item| convert_value(item) }
  else
    value
  end
end