Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #3

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
73d24c1
Bring Reader and some documentation up to date.
joseph Apr 8, 2011
4771969
Reader includes an option not to load the DTD.
joseph Apr 11, 2011
4c7668a
Sales rights.
joseph Apr 8, 2011
a78b43b
Organising source files into subdirs.
joseph Apr 11, 2011
3165256
Onix codes as first-class data objects.
joseph Apr 11, 2011
71d909c
Fleshing out the entire Product accessor suite for ONIX 2.1.
joseph Apr 11, 2011
8c94bbd
CodeListExtractor can output to pure ruby hashes as well as TSV.
joseph Apr 12, 2011
23209e0
Codelists are now pure Ruby hashes, loaded on demand.
joseph Apr 12, 2011
4e6e130
Tweaking require practices and gem packaging.
joseph Apr 12, 2011
a335c2b
Organising specs into directorys matching lib/onix/*.
joseph Apr 12, 2011
2b75795
Specs for Code and Element. Fixes for array accessor types in Element.
joseph Apr 12, 2011
b30c3c0
Removing the gem package rake task.
joseph Apr 12, 2011
18c4f85
Custom exceptions, no longer thrown if given invalid code value.
joseph Apr 12, 2011
957b384
More explanatory documentation for the code accessors in Element.
joseph Apr 12, 2011
676961a
Allow initializing Reader from StringIO.
joseph Apr 12, 2011
c634155
Allow ONIX::Product to be easily extended with "interpretation" modules.
joseph Apr 13, 2011
61b0b9f
More work on modelling ONIX structure.
joseph Apr 13, 2011
8a512a8
Bring Reader and some documentation up to date.
joseph Apr 8, 2011
fc12027
Reader includes an option not to load the DTD.
joseph Apr 11, 2011
b8b5f95
Sales rights.
joseph Apr 8, 2011
8b21316
Organising source files into subdirs.
joseph Apr 11, 2011
704a399
Onix codes as first-class data objects.
joseph Apr 11, 2011
9ad5493
Fleshing out the entire Product accessor suite for ONIX 2.1.
joseph Apr 11, 2011
65486cf
CodeListExtractor can output to pure ruby hashes as well as TSV.
joseph Apr 12, 2011
4ea847b
Codelists are now pure Ruby hashes, loaded on demand.
joseph Apr 12, 2011
eb7967d
Tweaking require practices and gem packaging.
joseph Apr 12, 2011
d86cecb
Organising specs into directorys matching lib/onix/*.
joseph Apr 12, 2011
708df40
Specs for Code and Element. Fixes for array accessor types in Element.
joseph Apr 12, 2011
26ee759
Removing the gem package rake task.
joseph Apr 12, 2011
fee433a
Custom exceptions, no longer thrown if given invalid code value.
joseph Apr 12, 2011
b6c4293
More explanatory documentation for the code accessors in Element.
joseph Apr 12, 2011
6a4efb2
Allow ONIX::Product to be easily extended with "interpretation" modules.
joseph Apr 13, 2011
fa37d2f
More work on modelling ONIX structure.
joseph Apr 13, 2011
7ba169d
Silencing a few deliberate STDERR messages in rspec output.
joseph Apr 14, 2011
dc0aa31
Tidying up after merge from upstream (0.8.6 -> 0.9.0).
joseph Apr 14, 2011
4f28e2c
Product#fetch and #fetch_all shortcut a common interpretation pattern.
joseph Apr 14, 2011
29a9fdf
Normaliser can process to a tempfile.
joseph Jun 11, 2011
154a2ea
Updating gemspec because people keep dicking with the Rubygems API.
joseph Sep 2, 2011
c18eb63
Finished transcribing xml attributes from ONIX 2.1 spec.
joseph Sep 27, 2011
7592904
Got specs passing. Removed need to initialise array accessors.
joseph Sep 27, 2011
1845c91
onix_boolean_flag is an accessor definition for stuff like <NoSeries/>
joseph Sep 27, 2011
732ffd5
Allow invalid codes from list if :enforce option explicitly false.
joseph Sep 28, 2011
aae1bf8
onix_spaced_code_from_lists - validate multiple country codes.
joseph Sep 28, 2011
a90835f
Merge branch 'master' of https://github.com/yob/onix into refactor-merge
joseph Sep 28, 2011
b5bd841
Religious text ONIX elements.
joseph Sep 28, 2011
15baf54
Better inheritance of xml_array_accessors.
joseph Sep 28, 2011
3840058
Product#main_subjects (plural) & typo in main_subject.
joseph Oct 7, 2011
7f1ae07
Removing superfluous andand dependency.
joseph Oct 17, 2011
e8312f4
Upgrading to latest versions of dependencies.
joseph Apr 16, 2012
2be3f4f
Typo in DiscountCoded.
joseph May 16, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use ree@onix
9 changes: 4 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ require "bundler"
Bundler.setup

require 'rake'
require 'rake/rdoctask'
require 'rdoc/task'
require 'rspec/core/rake_task'


desc "Default Task"
task :default => [ :spec ]

# run all rspecs
desc "Run all rspec files"
RSpec::Core::RakeTask.new("spec") do |t|
t.rspec_opts = ["--color", "--format progress"]
t.rspec_opts = ["-Ispec", "--color", "--format progress"]
end
desc 'Generate documentation'

desc "Generate documentation"
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'ONIX'
Expand Down
41 changes: 33 additions & 8 deletions bin/onix_extract_codelists
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
#!/usr/bin/ruby
# coding: utf-8

USAGE = "./onix_extract_codelists ONIX_BookProduct_CodeLists.xsd some_dir"
# NB: When testing locally, you can run this as:
#
# ruby -Ilib bin/onix_extract_codelists [options] xsd dir

require 'rubygems'
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
require "onix"
require 'optparse'

def parse_options
options = {}
optparse = OptionParser.new do |parser|
parser.banner = [
"Usage: onix_extract_codelists [options] xsd_path output_dir_path",
"",
" eg: onix_extract_codelists ONIX_BookProduct_CodeLists.xsd support/codes"
].join("\n")

options[:format] = :tsv
parser.on("-f", "--format FMT", "Write to format (TSV or Ruby)") do |fmt|
options[:format] = fmt.downcase.to_sym
end

unless ARGV.size == 2
puts USAGE
exit(1)
parser.on("-h", "--help", "Display this usage information") do
puts parser
exit
end
end
optparse.parse!
unless ARGV.size == 2
puts optparse
exit(1)
end
options
end

extractor = ONIX::CodeListExtractor.new(ARGV.shift)
options = parse_options

require "onix"
extractor = ONIX::CodeListExtractor.new(ARGV.shift, options[:format])
extractor.run(ARGV.shift)
7 changes: 7 additions & 0 deletions data/product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
<PublishingStatus>04</PublishingStatus>
<PublicationDate>19980901</PublicationDate>
<YearFirstPublished>1998</YearFirstPublished>
<RelatedProduct>
<RelationCode>13</RelationCode>
<ProductIdentifier>
<ProductIDType>15</ProductIDType>
<IDValue>9781742752020</IDValue>
</ProductIdentifier>
</RelatedProduct>
<Measure>
<MeasureTypeCode>08</MeasureTypeCode>
<Measurement>720 </Measurement>
Expand Down
35 changes: 35 additions & 0 deletions data/sales_rights.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Product>
<RecordReference>365-9780194351898</RecordReference>
<NotificationType>03</NotificationType>
<ProductIdentifier>
<ProductIDType>03</ProductIDType>
<IDValue>9780194351898</IDValue>
</ProductIdentifier>

<SalesRights>
<SalesRightsType>01</SalesRightsType>
<RightsTerritory>WORLD</RightsTerritory>
</SalesRights>

<SalesRights>
<SalesRightsType>02</SalesRightsType>
<RightsCountry>AU NZ</RightsCountry>
</SalesRights>

<SalesRights>
<SalesRightsType>01</SalesRightsType>
<RightsRegion>000</RightsRegion>
<RightsRegion>001</RightsRegion>
<RightsRegion>002</RightsRegion>
<RightsRegion>003</RightsRegion>
</SalesRights>

<NotForSale>
<RightsCountry>GB</RightsCountry>
<ProductIdentifier>
<ProductIDType>03</ProductIDType>
<IDValue>9780194312345</IDValue>
</ProductIdentifier>
</NotForSale>
</Product>
144 changes: 106 additions & 38 deletions lib/onix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'cgi'
require 'singleton'
require 'roxml'
require 'andand'

module ONIX
module Version #:nodoc:
Expand All @@ -15,6 +14,8 @@ module Version #:nodoc:
String = [Major, Minor, Tiny].join('.')
end

VERSION = ONIX::Version::String

class Formatters
def self.decimal
lambda do |val|
Expand Down Expand Up @@ -51,43 +52,110 @@ def self.two_digit
end
end
end

def self.space_separated
lambda { |val| [val.collect(&:to_s).join(" ")] if val }
end

def self.boolean
lambda { |val| "" if val }
end
end
end

# core files
# - ordering is important, classes need to be defined before any
# other class can use them
require File.join(File.dirname(__FILE__), "onix", "sender_identifier")
require File.join(File.dirname(__FILE__), "onix", "addressee_identifier")
require File.join(File.dirname(__FILE__), "onix", "header")
require File.join(File.dirname(__FILE__), "onix", "product_identifier")
require File.join(File.dirname(__FILE__), "onix", "series_identifier")
require File.join(File.dirname(__FILE__), "onix", "series")
require File.join(File.dirname(__FILE__), "onix", "title")
require File.join(File.dirname(__FILE__), "onix", "website")
require File.join(File.dirname(__FILE__), "onix", "contributor")
require File.join(File.dirname(__FILE__), "onix", "language")
require File.join(File.dirname(__FILE__), "onix", "subject")
require File.join(File.dirname(__FILE__), "onix", "audience_range")
require File.join(File.dirname(__FILE__), "onix", "imprint")
require File.join(File.dirname(__FILE__), "onix", "publisher")
require File.join(File.dirname(__FILE__), "onix", "other_text")
require File.join(File.dirname(__FILE__), "onix", "media_file")
require File.join(File.dirname(__FILE__), "onix", "sales_restriction")
require File.join(File.dirname(__FILE__), "onix", "stock")
require File.join(File.dirname(__FILE__), "onix", "price")
require File.join(File.dirname(__FILE__), "onix", "supply_detail")
require File.join(File.dirname(__FILE__), "onix", "market_representation")
require File.join(File.dirname(__FILE__), "onix", "measure")
require File.join(File.dirname(__FILE__), "onix", "product")
require File.join(File.dirname(__FILE__), "onix", "reader")
require File.join(File.dirname(__FILE__), "onix", "writer")

# product wrappers
require File.join(File.dirname(__FILE__), "onix", "simple_product")
require File.join(File.dirname(__FILE__), "onix", "apa_product")

# misc
require File.join(File.dirname(__FILE__), "onix", "lists")
require File.join(File.dirname(__FILE__), "onix", "normaliser")
require File.join(File.dirname(__FILE__), "onix", "code_list_extractor")

# Ordering is important here; classes need to be defined before any
# other class can use them.
[
# core files
"core/element",
"core/lists",
"core/code",

# identifier mappings
"elements/identifier",
"elements/sender_identifier",
"elements/addressee_identifier",
"elements/person_name_identifier",
"elements/product_identifier",
"elements/series_identifier",
"elements/work_identifier",
"elements/agent_identifier",
"elements/conference_sponsor_identifier",
"elements/copyright_owner_identifier",
"elements/location_identifier",
"elements/sales_outlet_identifier",
"elements/supplier_identifier",
"elements/text_item_identifier",

# other element mappings
"elements/name_base",
"elements/name",
"elements/person_date",
"elements/professional_affiliation",
"elements/product_form_feature",
"elements/product_classification",
"elements/audience",
"elements/batch_bonus",
"elements/complexity",
"elements/copyright_owner",
"elements/copyright_statement",
"elements/discount_coded",
"elements/main_subject",
"elements/market_date",
"elements/new_supplier",
"elements/on_order_detail",
"elements/page_run",
"elements/prize",
"elements/sales_outlet",
"elements/stock_quantity_coded",
"elements/text_item",
"elements/title",
"elements/website",
"elements/contributor",
"elements/series",
"elements/set",
"elements/conference_sponsor",
"elements/conference",
"elements/extent",
"elements/illustrations",
"elements/language",
"elements/subject",
"elements/audience_range",
"elements/imprint",
"elements/publisher",
"elements/other_text",
"elements/media_file",
"elements/sales_restriction",
"elements/sales_rights",
"elements/not_for_sale",
"elements/stock",
"elements/price",
"elements/reissue",
"elements/supply_detail",
"elements/market_representation",
"elements/measure",
"elements/bible",
"elements/religious_text_feature",
"elements/religious_text",
"elements/content_item",
"elements/product_base",
"elements/contained_item",
"elements/related_product",
"elements/product",

# more core files
"core/header",
"core/reader",
"core/writer",

# product wrappers
"wrappers/simple_product",
"wrappers/apa_product",

# utilities
"utils/normaliser",
"utils/code_list_extractor"
].each do |req|
require File.join("onix", req)
end
11 changes: 0 additions & 11 deletions lib/onix/addressee_identifier.rb

This file was deleted.

25 changes: 0 additions & 25 deletions lib/onix/audience_range.rb

This file was deleted.

69 changes: 0 additions & 69 deletions lib/onix/code_list_extractor.rb

This file was deleted.

Loading