Class: DMM::Response::ItemInfo
- Inherits:
-
Object
- Object
- DMM::Response::ItemInfo
- Defined in:
- lib/ruby-dmm/response/item_info.rb
Constant Summary collapse
- ATTRIBUTE_SINGLE =
[:series, :maker, :label, :director, :author, :type, :size, :genre, :color]
- ATTRIBUTE_MULTIPLE =
{ :keywords => :keyword, :actresses => :actress, :actors => :actor, :artists => :artist, :fighters => :fighter, }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(item_info) ⇒ ItemInfo
constructor
A new instance of ItemInfo.
Constructor Details
#initialize(item_info) ⇒ ItemInfo
Returns a new instance of ItemInfo.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby-dmm/response/item_info.rb', line 16 def initialize(item_info) ATTRIBUTE_SINGLE.inject({}) {|h,k| h.merge(k => k)}.merge({}).each do |attribute, key| value = self.class.integrate(item_info[key]) value = value.first if value instance_variable_set("@#{attribute}", value) end ATTRIBUTE_MULTIPLE.each do |attribute, key| value = self.class.integrate(item_info[key]) instance_variable_set("@#{attribute}", value) end end |
Class Method Details
.integrate(h) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby-dmm/response/item_info.rb', line 28 def self.integrate(h) h && [h].flatten.inject({}) {|hash, params| id, key = params["id"].split('_') hash[id] ||= {"id" => id} if key hash[id].merge!(key => params["name"]) else hash[id].merge!("name" => params["name"]) end hash }.values end |