module Otis::HashContent

This module holds a collection of utilitie methods for Hash objects

Public Class Methods

included(base) click to toggle source
# File lib/otis/hash_content.rb, line 5
def self.included(base)
  base.extend(ClassExtension)
end
new(attrs = {}) click to toggle source
Calls superclass method
# File lib/otis/hash_content.rb, line 9
def initialize(attrs = {})
  @response = root(attrs)
  super(@response)
end

Private Instance Methods

root(attrs) click to toggle source
# File lib/otis/hash_content.rb, line 15
def root(attrs)
  return attrs unless self.respond_to?(:path)
  attrs = sub_tree(attrs)
  if self.respond_to?(:new_root)
    Hash[new_root.to_sym => attrs]
  else
    attrs
  end
end
sub_tree(attrs) click to toggle source

Navigates in the Hash tree and return a subtree based on the path list

# File lib/otis/hash_content.rb, line 26
def sub_tree(attrs)
  path.inject(attrs){ |res, el| res[el]}
end