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

Conversation

bbmreed
Copy link

@bbmreed bbmreed commented Nov 23, 2022

I wanted to open a PR from a fork (https://github.com/BookBub/im_onix) in case it's helpful, feel free to dismiss.

  • Small update to support ruby 2.7 (need an explicit require for SimpleDelegator)
  • ContributorRoles is now a many elements field, rather than single. A Contributor can have multiple ContributorRoles: eg Author & Narrator. Most publishers just create full Contributor's per-role, but others, if the rest of the information is shared (aka it's the same person), they will just add additional ContributorRoles
  • Adding the ability to use Nokogiri::XML::Reader rather than a full Nokogiri::XML.parse - the latter pulls the entire onix file into memory first, while the Reader will stream each node into memory, so is overall less memory intensive. This matches Cacofonix's strategy as well, which under benchmarking was faster than im_onix.

@@ -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

@julbouln
Copy link
Member

Hi,

Nice contribution ! Just be careful not to break the API so we can integrate it in main branch.

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants