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

Publication ranges #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

slimdave
Copy link
Collaborator

This adds the ability to use an ISBN13 to generate a publication range object, which can then generate the complete list of valid ISBN13s for that registrant element.

A few other methods are included, mostly for display purposes.

Squashed commits:
[68dfa1e] Add publication ranges, for calculating all ISBN13s for a registrant's prefix
@ragalie
Copy link
Owner

ragalie commented Dec 26, 2017

Thanks @slimdave !

I haven't had a chance to look this over yet, but one thing that immediately jumps out is that it would be nice if PublicationRange was Enumerable. Since some of the registrant elements are pretty large, that would be helpful if someone needed to retrieve a subset of the whole (e.g. first 50 ISBNs in the range), since they could use lazy to avoid storing the entire range in memory.

@slimdave
Copy link
Collaborator Author

That's a good idea. Done.

@@ -45,6 +45,16 @@ def isbn13
'978' + isbn[0..-2] + isbn_13_checksum
end

def isbn13_checksum_corrected
Copy link
Owner

Choose a reason for hiding this comment

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

It seems like most of the methods use isbn_13 rather than isbn13. My preference would be to standardize on isbn_13 (and isbn_10), and to open a separate PR to rename the anomalous isbn13 method.

Copy link
Owner

Choose a reason for hiding this comment

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

A better name for this might also be something like isbn_13_with_corrected_checksum that makes clear that an ISBN is being returned, and not a checksum.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed

end

def publication_numbers
(0..(number_of_publications-1))
Copy link
Owner

Choose a reason for hiding this comment

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

Would be best to add spaces around the - sign like you do in other places in this class.

end

def to_prefix
(prefix.to_i+1) * multiplier - 1
Copy link
Owner

Choose a reason for hiding this comment

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

Spaces around operator here too.

end

def from
Lisbn.new((from_prefix*10).to_s).isbn13_checksum_corrected
Copy link
Owner

Choose a reason for hiding this comment

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

Spaces around operator here too.

end

def to
Lisbn.new((to_prefix*10).to_s).isbn13_checksum_corrected
Copy link
Owner

Choose a reason for hiding this comment

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

Spaces around operator here too.

private
attr_reader :seed_isbn13

def multiplier
Copy link
Owner

Choose a reason for hiding this comment

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

This method seems to have the same return value as the number_of_publications method. Should we pick one?

@seed_isbn13 = Lisbn.new(seed_isbn13)
end

def parts
Copy link
Owner

Choose a reason for hiding this comment

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

The naming of this method is confusing. Maybe registration_parts?

@@ -0,0 +1,57 @@
class Lisbn < String
class PublicationRange
Copy link
Owner

Choose a reason for hiding this comment

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

This mechanism is a bit hard to understand, but I think from_prefix is basically:

seed_isbn13.parts[0..2].join + "0" * (12 - prefix.size) + checksum

and to_prefix is:

seed_isbn13.parts[0..2].join + "9" * (12 - prefix.size) + checksum

Is it easier to implement and think about by manipulating the parts (as a string), rather than doing the integer multiplication approach?

@ragalie
Copy link
Owner

ragalie commented Feb 22, 2018

@slimdave I made a few comments above.

I also added you as a collaborator on the repository, thanks for your contributions! Feel free to merge in minor changes like updates to the ranges file as you see fit. Probably a good idea to continue to request review on larger updates such as this. I'll try to be better about reviewing them promptly.

Thanks again!

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