lib/uatu/resource.rb in uatu-marvel-0.0.2 vs lib/uatu/resource.rb in uatu-marvel-0.1.0
- old
+ new
@@ -3,45 +3,47 @@
def initialize(original_hash)
super(improve_values(underscore_keys(original_hash)))
end
+ private
+
# Underscore names of the Hash. I mean... this is Ruby, right?.
def underscore_keys(hash)
_hash = {}
- hash.each do |k, v|
- _hash[k.to_s.underscore] = if v.is_a?(Hash)
- underscore_keys(v)
- elsif v.is_a?(Array) and v.first.is_a?(Hash)
- v.map{|h| underscore_keys(h)}
+ 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
- v
+ value
end
end
_hash
end
# 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.
def improve_values(hash)
_hash = {}
- hash.each do |k,v|
- _hash[k] = if k.to_s=='thumbnail'
- [v['path'],v['extension']].join('.')
- elsif v.is_a?(Hash)
- Hashie::Mash.new(v)
+ 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
- v
+ value
end
end
_hash
end
end
+end
- class Character < Resource ; end
- class Event < Resource ; end
- class Comic < Resource ; end
- class Story < Resource ; end
- class Serie < Resource ; end
- class Creator < Resource ; end
-end
\ No newline at end of file
+class Uatu::Character < Uatu::Resource ; end
+class Uatu::Event < Uatu::Resource ; end
+class Uatu::Comic < Uatu::Resource ; end
+class Uatu::Story < Uatu::Resource ; end
+class Uatu::Serie < Uatu::Resource ; end
+class Uatu::Creator < Uatu::Resource ; end