lc_callnumber 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -14
- data/lib/lc_callnumber/lcc.rb +4 -2
- data/lib/lc_callnumber/version.rb +1 -1
- data/test/test_lc_callnumber.rb +36 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c4edf521e42e002e663b7a49e81f71ca61c075
|
4
|
+
data.tar.gz: 474f6b3cd2f77448531bfd05d5dca10cb3a1d6fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06eabe768f5d7f60c134f6f5da1f372a063ba90a85994dc6d6bd290c1fb12cc980d59d7117f45ef6139ce388cd5e892fa971ad365ba2b782bde74ecab828619f
|
7
|
+
data.tar.gz: df316647d0d8a9bccf6ebc7f97c1f581f90e4b122fb2f0fd843f7e45952116f694b3e630dd742efd2da4b21709738cf73628b88a04c5ed88444a9d66fbe1d182
|
data/README.md
CHANGED
@@ -9,7 +9,6 @@ Includes simple getters/setters and a PEG parser.
|
|
9
9
|
## Things that aren't yet done
|
10
10
|
|
11
11
|
* Normalization: create a string that can be compared with other normalized strings to correctly order the call numbers
|
12
|
-
* Implement `<=>` so call number object can be compared.
|
13
12
|
* Much better testing
|
14
13
|
|
15
14
|
|
@@ -30,20 +29,21 @@ The OCLC has [a page explaining how LC Call Numbers are composed](http://www.ocl
|
|
30
29
|
|
31
30
|
For purposes of this class, an LC Call Number consists of the following parts. Only the first two are required; everything else is optional.
|
32
31
|
|
33
|
-
* __Letter(s).__ One or more letters
|
34
|
-
* __Digit(s).__ One or more digits, optionally with a decimal point.
|
35
|
-
* __Doon1 (_Date Or Other Number_)__. [Note: no one but me calls it a 'doon', but I needed a term and there wasn't another]. Relatively rare as these things go, a DOON is used to represent the date the work is _about_ (as opposed to, say, the year it was published) or, in some cases, an identifier for an army division or group (say, "12th" for the US Army Twelfth Infantry).
|
36
|
-
* __First
|
37
|
-
* __Doon2__. Another date or other number
|
38
|
-
* __"Extra" Cutters__. The 2nd through
|
39
|
-
* __Year__. The year of publication
|
40
|
-
* __"Rest"__. Everything and anything else.
|
32
|
+
* __Letter(s).__ One or more letters.
|
33
|
+
* __Digit(s).__ One or more digits, optionally with a decimal point.
|
34
|
+
* __Doon1 (_Date Or Other Number_)__. [Note: no one but me calls it a 'doon', but I needed a term and there wasn't another]. Relatively rare as these things go, a DOON is used to represent the date the work is _about_ (as opposed to, say, the year it was published) or, in some cases, an identifier for an army division or group (say, "12th" for the US Army Twelfth Infantry).
|
35
|
+
* __First Cutter__. The first "Cutter number," consisting of a letter followed by one or more digits. The first Cutter is always supposed to be preceded by a dot, but, you know, isn't always.
|
36
|
+
* __Doon2__. Another date or other number.
|
37
|
+
* __"Extra" Cutters__. The 2nd through nth Cutter numbers, lumped together because we don't have to worry about them getting interspersed with doons.
|
38
|
+
* __Year__. The year of publication.
|
39
|
+
* __"Rest"__. Everything and anything else.
|
40
|
+
|
41
41
|
|
42
42
|
## Usage
|
43
43
|
|
44
44
|
In general, you won't be building these things up by hand; you'll try to parse them.
|
45
45
|
|
46
|
-
Note that in the case below, while in theory this could be a callnumber with a single
|
46
|
+
Note that in the case below, while in theory this could be a callnumber with a single Cutter followed by a doon2 and no year, we presume the '1990' is a year and don't call it a doon.
|
47
47
|
|
48
48
|
~~~ruby
|
49
49
|
|
@@ -61,6 +61,10 @@ lc.rest #=> nil
|
|
61
61
|
lc = LCCallNumber.parse('A .B3') #=> LCCallNumber::UnparseableCallNumber
|
62
62
|
lc.valid? #=> false
|
63
63
|
|
64
|
+
a = LCCallNumber.parse("B 528.S43")
|
65
|
+
b = LCCallNumber.parse("B 528.S298")
|
66
|
+
a <=> b # -1
|
67
|
+
|
64
68
|
~~~
|
65
69
|
|
66
70
|
|
@@ -79,13 +83,10 @@ Or install it yourself as:
|
|
79
83
|
$ gem install lc_callnumber
|
80
84
|
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
86
|
## Contributing
|
86
87
|
|
87
88
|
1. Fork it
|
88
89
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
89
90
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
90
91
|
4. Push to the branch (`git push origin my-new-feature`)
|
91
|
-
5. Create new
|
92
|
+
5. Create new pull request
|
data/lib/lc_callnumber/lcc.rb
CHANGED
@@ -213,7 +213,8 @@ module LCCallNumber
|
|
213
213
|
firstcutter_cmp = firstcutter.letter <=> other.firstcutter.letter
|
214
214
|
# If that didn't help, compare the digits
|
215
215
|
if firstcutter_cmp == 0
|
216
|
-
|
216
|
+
# Compare numbers as strings, because S43 < S298
|
217
|
+
firstcutter_cmp = firstcutter.digits.to_s <=> other.firstcutter.digits.to_s
|
217
218
|
end
|
218
219
|
# If that didn't help, if other has an extra_cutter, it is last
|
219
220
|
if firstcutter_cmp == 0
|
@@ -249,7 +250,8 @@ module LCCallNumber
|
|
249
250
|
extra_cutters_cmp = extra_cutters[i].letter <=> other.extra_cutters[i].letter
|
250
251
|
# If that didn't help, compare the digits
|
251
252
|
if extra_cutters_cmp == 0
|
252
|
-
|
253
|
+
# Compare numbers as strings, because S43 < S298
|
254
|
+
extra_cutters_cmp = extra_cutters[i].digits.to_s <=> other.extra_cutters[i].digits.to_s
|
253
255
|
end
|
254
256
|
# If that didn't help, if self has no more extra_cutters but other does, self is first
|
255
257
|
if extra_cutters_cmp == 0
|
data/test/test_lc_callnumber.rb
CHANGED
@@ -29,24 +29,41 @@ describe "Basics" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "Sorting" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert (
|
44
|
-
|
45
|
-
|
46
|
-
assert (
|
47
|
-
|
48
|
-
|
49
|
-
assert (
|
50
|
-
|
32
|
+
a1 = LCCallNumber.parse("A 50")
|
33
|
+
a2 = LCCallNumber.parse("A 7")
|
34
|
+
b1 = LCCallNumber.parse("B 528.S43")
|
35
|
+
b2 = LCCallNumber.parse("B 528.S298")
|
36
|
+
q1 = LCCallNumber.parse("QA 500")
|
37
|
+
q2 = LCCallNumber.parse("QA 500.M500")
|
38
|
+
q3 = LCCallNumber.parse("QA 500.M500 T59")
|
39
|
+
q4 = LCCallNumber.parse("QA 500.M500 T60")
|
40
|
+
q5 = LCCallNumber.parse("QA 500.M500 T60 A1")
|
41
|
+
q6 = LCCallNumber.parse("QA 500.M500 T60 Z54")
|
42
|
+
it "knows call numbers equal themselves" do
|
43
|
+
assert (a1 <=> a1) == 0 # A == A (very Aristotelian)
|
44
|
+
end
|
45
|
+
it "sorts first letters properly" do
|
46
|
+
assert (a2 <=> q1) == -1 # A < Q
|
47
|
+
end
|
48
|
+
it "sorts first digits properly" do
|
49
|
+
assert (a1 <=> a2) == 1 # A 50 > A 7
|
50
|
+
end
|
51
|
+
it "sorts when one item has no Cutter" do
|
52
|
+
assert (q1 <=> q2) == -1 # QA 500 < QA 500.M500
|
53
|
+
end
|
54
|
+
it "sorts first Cutters properly" do
|
55
|
+
assert (b1 <=> b2) == 1 # S43 > S298
|
56
|
+
end
|
57
|
+
it "sorts when one item has a Cutter, one an extra Cutter" do
|
58
|
+
assert (q2 <=> q3) == -1 # M500 < M500 T59
|
59
|
+
end
|
60
|
+
it "sorts properly on second Cutters" do
|
61
|
+
assert (q3 <=> q4) == -1 # T59 < T60
|
62
|
+
end
|
63
|
+
it "sorts when one item has two Cutters, one has three" do
|
64
|
+
assert (q4 <=> q5) == -1 # M500 T60 < M500 T60 A1
|
65
|
+
end
|
66
|
+
it "sorts properly on third Cutters" do
|
67
|
+
assert (q5 <=> q6) == -1 # A1 < Z54
|
51
68
|
end
|
52
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lc_callnumber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Dueber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|