Module: LCCallNumber
- Defined in:
- lib/lc_callnumber/lcc.rb,
lib/lc_callnumber/parser.rb,
lib/lc_callnumber/version.rb
Defined Under Namespace
Classes: CallNumber, Cutter, Decimal, FirstCutterSet, Lead, Parser, Transform, UnparseableCallNumber
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
Class Method Details
.parse(i) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lc_callnumber/lcc.rb', line 8 def self.parse(i) return UnparseableCallNumber.new(i) if i.nil? i.chomp! i.strip! orig = i i.gsub!(/\[(.+)\]/, "$1") i.gsub!('\\', ' ') # We also have a bunch that start with a slash and have slashes where you'd # expect logical breaks. Don't know why. if i =~ /\A\// i.gsub!('/', ' ') end # Ditch leading + or * i.gsub!(/\A[+*]/, '') # Strip off any leading/trailing spaces and upcase it i.strip! i.upcase! # Don't bother if it starts with a number, four letters, or the string 'law' # Don't bother if there's no numbers at all if (/\A\d/.match i) or (/\A[[:alpha:]]{4}/.match i) or (/\ALAW/i.match i) or !(/\d/.match i) return UnparseableCallNumber.new(orig) end begin p = @parser.parse(i) # puts p lc = @transformer.apply(p) lc.original_string = orig return lc rescue Parslet::ParseFailed => e return UnparseableCallNumber.new(orig) end end |