Sha256: 8d7ea4946512dd0de8d695536cee9a784389187df5fbed5285c185837c77a564

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

# coding: utf-8

module ONIX
  class Set
    include ROXML

    xml_name "Set"

    xml_accessor :product_identifiers, :from => "ProductIdentifier", :as => [ONIX::ProductIdentifier]
    xml_accessor :title_of_set, :from => "TitleOfSet"
    
    def initialize
      self.product_identifiers = []
    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
    
    # 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
    
    # 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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
milkfarm-onix-0.8.8 lib/onix/set.rb
milkfarm-onix-0.8.7 lib/onix/set.rb
milkfarm-onix-0.8.6 lib/onix/set.rb
milkfarm-onix-0.8.5 lib/onix/set.rb
milkfarm-onix-0.8.3 lib/onix/set.rb