Permalink
Browse files

started work on a brand new ONIX mapping library

  • Loading branch information...
0 parents commit e41823b98c26663d1be38fd9d35220664a96b749 @yob committed Jun 11, 2008
Showing with 105 additions and 0 deletions.
  1. +23 −0 data/rba_FANT.xml
  2. +12 −0 examples/read.rb
  3. +8 −0 lib/onix.rb
  4. +8 −0 lib/onix/header.rb
  5. +8 −0 lib/onix/message.rb
  6. +29 −0 lib/onix/product.rb
  7. +8 −0 lib/onix/product_identifier.rb
  8. +9 −0 lib/onix/title.rb
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE ONIXMessage SYSTEM "http://www.editeur.org/onix/2.1/reference/onix-international.dtd">
+<ONIXMessage>
+<Header>
+ <FromCompany>Sample Company</FromCompany>
+ <FromPerson>Sample Company</FromPerson>
+</Header>
+<Product>
+ <RecordReference>9781842021323</RecordReference>
+ <NotificationType>03</NotificationType>
+ <ProductIdentifier>
+ <ProductIDType>03</ProductIDType>
+ <IDValue>9781842021323</IDValue>
+ </ProductIdentifier>
+ <ProductForm></ProductForm>
+ <NoSeries/>
+ <Title>
+ <TitleType>01</TitleType>
+ <TitleText>In Fashion (beacons)</TitleText>
+ </Title>
+ <NoEdition/>
+</Product>
+</ONIXMessage>
@@ -0,0 +1,12 @@
+$LOAD_PATH << File.join(File.dirname(__FILE__), "..","lib")
+require 'onix'
+
+filename = File.join(File.dirname(__FILE__), "..","data","rba_FANT.xml")
+msg = ONIX::Message.load_from_file(filename)
+puts msg.header.inspect
+puts
+msg.products.each do |p|
+ puts p.best_id + " - " + p.best_title
+ puts p.inspect
+ puts
+end
@@ -0,0 +1,8 @@
+require 'rubygems'
+require 'xml/mapping'
+
+require File.join(File.dirname(__FILE__), "onix", "header")
+require File.join(File.dirname(__FILE__), "onix", "product_identifier")
+require File.join(File.dirname(__FILE__), "onix", "title")
+require File.join(File.dirname(__FILE__), "onix", "product")
+require File.join(File.dirname(__FILE__), "onix", "message")
@@ -0,0 +1,8 @@
+module ONIX
+ class Header
+ include XML::Mapping
+
+ text_node :from_company, "FromCompany"
+ text_node :from_person, "FromPerson"
+ end
+end
@@ -0,0 +1,8 @@
+module ONIX
+ class Message
+ include XML::Mapping
+
+ object_node :header, "Header", :class => ONIX::Header
+ array_node :products, "Product", :class => ONIX::Product
+ end
+end
@@ -0,0 +1,29 @@
+module ONIX
+ class Product
+ include XML::Mapping
+
+ text_node :record_reference, "RecordReference"
+ numeric_node :notification_type, "NotificationType"
+ array_node :product_identifiers, "ProductIdentifier", :class => ONIX::ProductIdentifier
+ text_node :product_form, "ProductForm"
+ text_node :series, "Series", :optional => true
+ text_node :edition, "Edition", :optional => true
+ array_node :titles, "Title", :class => ONIX::Title
+
+ def best_id
+ values = {}
+ product_identifiers.each do |id|
+ values[id.product_id_type] = id.id_value
+ end
+ values[3] || values[2] || values[1]
+ end
+
+ def best_title
+ values = {}
+ titles.each do |title|
+ values[title.title_type] = title.title_text
+ end
+ values[3] || values[2] || values[1]
+ end
+ end
+end
@@ -0,0 +1,8 @@
+module ONIX
+ class ProductIdentifier
+ include XML::Mapping
+
+ numeric_node :product_id_type, "ProductIDType"
+ text_node :id_value, "IDValue"
+ end
+end
@@ -0,0 +1,9 @@
+module ONIX
+ class Title
+ include XML::Mapping
+
+ numeric_node :title_type, "TitleType"
+ text_node :title_text, "TitleText"
+
+ end
+end

0 comments on commit e41823b

Please sign in to comment.