class OpenprojectApi::ObjectifiedHash

Public Class Methods

new(hash) click to toggle source
# File lib/openproject_api/objectified_hash.rb, line 5
def initialize(hash)
  @hash = hash
  @data = hash.each_with_object({}) do |(key, value), data|
    value          = self.class.new(value) if value.is_a? Hash
    value          = value.map { |v| v.is_a?(Hash) ? self.class.new(v) : v } if value.is_a? Array
    data[key.to_s] = value
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/openproject_api/objectified_hash.rb, line 23
def [](key)
  @data[key]
end
inspect() click to toggle source
# File lib/openproject_api/objectified_hash.rb, line 19
def inspect
  "#<#{self.class}:#{object_id} {hash: #{@hash.inspect}}"
end
to_h()
Alias for: to_hash
to_hash() click to toggle source
# File lib/openproject_api/objectified_hash.rb, line 14
def to_hash
  @hash
end
Also aliased as: to_h

Private Instance Methods

method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# File lib/openproject_api/objectified_hash.rb, line 29
def method_missing(method_name, *args, &block)
  if @data.key?(method_name.to_s)
    @data[method_name.to_s]
  elsif @data.respond_to?(method_name)
    @data.send(method_name, *args, &block)
  else
    super
  end
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/openproject_api/objectified_hash.rb, line 39
def respond_to_missing?(method_name, include_private = false)
  @hash.keys.map(&:to_sym).include?(method_name.to_sym) || super
end