class Uatu::Resource

Public Class Methods

new(original_hash) click to toggle source
Calls superclass method
# File lib/uatu/resource.rb, line 4
def initialize(original_hash)
  super(improve_values(underscore_keys(original_hash)))
end

Private Instance Methods

improve_values(hash) click to toggle source

We change the hashes to mashes (Hashie::Mash) so it's easier to manipulate The 'thumbnail' hash drives me crazy, we convert it to a single value.

# File lib/uatu/resource.rb, line 27
def improve_values(hash)
  _hash = {}
  hash.each do |key, value|
    _hash[key] = if key.to_s=='thumbnail' && !value.nil?
      [value['path'],value['extension']].join('.')
    elsif value.is_a?(Hash)
      Hashie::Mash.new(value)
    else
      value
    end
  end
  _hash
end
underscore_keys(hash) click to toggle source

Underscore names of the Hash. I mean… this is Ruby, right?.

# File lib/uatu/resource.rb, line 11
def underscore_keys(hash)
  _hash = {}
  hash.each do |key, value|
    _hash[key.to_s.underscore] = if value.is_a?(Hash)
      underscore_keys(value)
    elsif value.is_a?(Array) and value.first.is_a?(Hash)
      value.map{|h| underscore_keys(h)}
    else
      value
    end
  end
  _hash
end