Class: DMM::Response::ItemInfo
- Inherits:
-
Object
- Object
- DMM::Response::ItemInfo
- Defined in:
- lib/ruby-dmm/response/item_info.rb
Constant Summary collapse
- SINGLE_VALUE_ATTRIBUTES =
[ :author, :color, :director, :genre, :label, :maker, :series, :size, :type, ]
- MULTIPLE_VALUES_ATTRIBUTES =
{ :actors => :actor, :actresses => :actress, :artists => :artist, :fighters => :fighter, :keywords => :keyword, }
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.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby-dmm/response/item_info.rb', line 26 def initialize(item_info) SINGLE_VALUE_ATTRIBUTES.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 MULTIPLE_VALUES_ATTRIBUTES.each do |attribute, key| value = self.class.integrate(item_info[key]) instance_variable_set("@#{attribute}", value) end end |
Class Method Details
.integrate(h) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby-dmm/response/item_info.rb', line 38 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 |