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

enhancements for Onix 3 support #108

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/onix/contributor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module ONIX
class Contributor < SubsetDSL
element "SequenceNumber", :integer, :cardinality => 0..1
element "ContributorRole", :subset, :shortcut => :role, :cardinality => 1..n
elements "ContributorRole", :subset, :shortcut => :roles, :cardinality => 1..n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid API break, it would be nice to add a singular role method like for place https://github.com/immateriel/im_onix/blob/master/lib/onix/contributor.rb#L49

elements "FromLanguage", :subset, :klass => "LanguageCode", :cardinality => 0..n
elements "ToLanguage", :subset, :klass => "LanguageCode", :cardinality => 0..n

Expand Down
21 changes: 18 additions & 3 deletions lib/onix/onix_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ def open(arg, force_encoding = nil)
xml
end

def reader(file_path)
@reader = Nokogiri::XML::Reader(File.open(file_path, 'r'))
end

def each(&block)
@reader.each do |node|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add

return unless @reader

before the iteration to avoid an exception if reader has not been called ?

if @reader.node_type == 1 && @reader.name == "Product"
element = Nokogiri::XML(@reader.outer_xml).at('Product')
yield self.product_klass.parse(element)
end
end
end

# release as an integer eg: 210, 300, 301
# @return [Number]
def version
Expand All @@ -125,13 +138,15 @@ def detect_release(element)
end

def set_release_from_xml(node, force_release)
if force_release
@release = force_release.to_s
return
end

@release = node["release"]
unless @release
@release = detect_release(node)
end
if force_release
@release = force_release.to_s
end
end

def product_klass
Expand Down
3 changes: 2 additions & 1 deletion lib/onix/subset.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'forwardable'
require 'cgi'
require 'delegate'

module ONIX
class ShortToRef
Expand Down Expand Up @@ -492,4 +493,4 @@ def parse(n)
end
end
end
end
end