lib/rumblr/client.rb in hexorx-rumblr-0.0.3 vs lib/rumblr/client.rb in hexorx-rumblr-0.0.4
- old
+ new
@@ -52,11 +52,11 @@
hash['tags'] << child.content if (child.name[/tag/])
hash[child.name] = child.content
hash
end
# merge hashes, clean out cruft
- inner_attrs = cleanup_hash(subclass_attrs)
+ inner_attrs = cleanup_hash(subclass_attrs,post_attrs[:type])
inner_attrs.delete(:text)
inner_attrs.delete(:tag)
post_attrs.merge!(inner_attrs)
# turn attributes into proper model
klass = Rumblr.const_get(Post::TYPES[post_attrs[:type]])
@@ -126,12 +126,12 @@
raw_user_attributes = doc.find('//tumblr/user').first.attributes.to_h
user_attributes = cleanup_hash(raw_user_attributes)
user_attributes.merge!(:tumblelogs => tumblelogs)
end
- def cleanup_hash(attrs={})
+ def cleanup_hash(attrs={},type=nil)
clean_attrs = attrs.inject({}) do |hash,(key,value)|
- mapped_key = key.gsub(/-/,'_').to_sym
+ mapped_key = (key.split('-') - [type]).join('_').to_sym
mapped_value = case value
when /($1^|$yes^)/ then true
when /($0^|$no^)/ then false
else value
end