Created
July 31, 2011 17:50
-
-
Save betawaffle/1117014 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_isbn | |
return if isbn.nil? | |
x = 4 | |
case isbn[0..2].to_i | |
when 0..19, 100..109 then x = 2 | |
when 20..69, 110..139 then x = 3 | |
when 70..84, 140..154 then x = 4 | |
when 85..89, 155..185 then x = 5 | |
when 90..95, 187..198 then x = 6 | |
when 95..99 then x = 7 | |
when 186, 199 | |
case isbn[1..4].to_i | |
when 8600..8697 then x = 5 | |
when 8698..8699, 9900..9989 then x = 6 | |
when 9990..9999 then x = 7 | |
end | |
else | |
# Non-English | |
return | |
end | |
isbn = "#{isbn[0]}-#{isbn[1..x]}-#{isbn[(x+1)..8]}-#{isbn[9]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment