lib/onix/set.rb in milkfarm-onix-0.8.8 vs lib/onix/set.rb in milkfarm-onix-0.8.9
- old
+ new
@@ -1,76 +1,28 @@
# coding: utf-8
module ONIX
class Set
include ROXML
+ include ONIX::ProductIdentifiers
xml_name "Set"
- xml_accessor :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
+ xml_reader :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
xml_accessor :title_of_set, :from => "TitleOfSet"
- def initialize
- self.product_identifiers = []
+ def initialize(options = {})
+ options.symbolize_keys!
+ self.initialize_product_identifiers(options) # Must be called to setup @product_identifiers array
end
- # retrieve the proprietary set ID
- def proprietary_set_id
- product_identifier(1).andand.id_value
- end
-
- # set a new proprietary set ID
- def proprietary_set_id=(id)
- product_identifier_set(1, id)
- end
+ # Following methods removed os of gem 0.8.9 (aliased for backwards compatible):
+ alias_method :proprietary_set_id, :proprietary_id
+ alias_method :proprietary_set_id=, :proprietary_id=
- # retrieve the 10-digit isbn
- def isbn10
- product_identifier(2).andand.id_value
- end
-
- # set a new 10-digit isbn
- def isbn10=(id)
- product_identifier_set(2, id)
- end
+ # Following methods removed os of gem 0.8.9 (NOT backwards compatible):
+ # original method -> replacement method
+ # product_identifier(type) -> see product_identifiers.rb (eg, use isbn, lccn...)
+ # product_identifier_set(type, value) -> see product_identifiers.rb (eg, use isbn=, lccn=...)
- # retrieve the 13-digit isbn
- def isbn
- product_identifier(15).andand.id_value
- end
-
- # set a new 13-digit isbn
- def isbn=(id)
- product_identifier_set(15, id)
- end
-
- # retrieve the lccn
- def lccn
- product_identifier(13).andand.id_value
- end
-
- # set a new lccn
- def lccn=(id)
- product_identifier_set(13, id)
- end
-
- # retrieve the value of a particular ID
- def product_identifier(type)
- identifier = product_identifiers.find { |id| id.product_id_type == type }
- end
-
- # set the value of a particular ID
- def product_identifier_set(type, value)
- product_identifier_id = product_identifiers.find { |id| id.product_id_type == type }
-
- # create a new set identifier record if we need to
- if product_identifier_id.nil?
- product_identifier_id = ONIX::ProductIdentifier.new
- end
-
- product_identifier_id.product_id_type = type
- product_identifier_id.id_value = value
-
- product_identifiers << product_identifier_id
- end
end
end