lc_callnumber 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d173a4ec0a1b4ba26c0beec642a3f66b845c67d4
4
- data.tar.gz: 41a42a08153cb57f4f0c775794cbf72c56890369
3
+ metadata.gz: a8c4edf521e42e002e663b7a49e81f71ca61c075
4
+ data.tar.gz: 474f6b3cd2f77448531bfd05d5dca10cb3a1d6fc
5
5
  SHA512:
6
- metadata.gz: 3aa66113e6ac592735e4bfdba100b7b174635054dc26b0d136d749329b48df6957233bef6d426e50d07ab794a0e010b23cdcbd6f04f1ce52703d28ad9b53fe1e
7
- data.tar.gz: 686dc9b45975782c5c426af6430e0bec8d08c21fa41a6aff5dd4b7b768a2871fd51d8bfb48f1a43bb8fe0b1c36e286db1319131c35f272f586d8b96c2899cf43
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 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.
37
- * __Doon2__. Another date or other number
38
- * __"Extra" Cutters__. The 2nd through Nth Cutter numbers, lumped together because we don't have to worry about them getting interspersed with doons.
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 cutter followed by a doon2 and no year, we presume the '1990' is a year and don't call it a doon.
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 Pull Request
92
+ 5. Create new pull request
@@ -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
- firstcutter_cmp = firstcutter.digits <=> other.firstcutter.digits
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
- extra_cutters_cmp = extra_cutters[i].digits <=> other.extra_cutters[i].digits
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
@@ -1,3 +1,3 @@
1
1
  module LCCallNumber
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -29,24 +29,41 @@ describe "Basics" do
29
29
  end
30
30
 
31
31
  describe "Sorting" do
32
- it "sorts call numbers properly" do
33
- a1 = LCCallNumber.parse("A 50")
34
- a2 = LCCallNumber.parse("A 7")
35
- q1 = LCCallNumber.parse("QA 500")
36
- q2 = LCCallNumber.parse("QA 500.M500")
37
- q3 = LCCallNumber.parse("QA 500.M500 T59")
38
- q4 = LCCallNumber.parse("QA 500.M500 T60")
39
- q5 = LCCallNumber.parse("QA 500.M500 T60 A1")
40
- q6 = LCCallNumber.parse("QA 500.M500 T60 Z54")
41
- assert (a1 <=> a1) == 0 # a1 is a1
42
- assert (a1 <=> a2) == 1 # a1 > a2
43
- assert (a2 <=> q1) == -1 # a2 < q1
44
- assert (q1 <=> q2) == -1 # q1 < q2
45
- assert (q2 <=> q3) == -1 # q2 < q3
46
- assert (q3 <=> q3) == 0 # q3 is q3
47
- assert (q3 <=> q4) == -1 # q3 < q4
48
- assert (q4 <=> q5) == -1 # q4 < q5
49
- assert (q5 <=> q6) == -1 # q5 < q6
50
- # Is there some way to put some test numbers into an array, sort it, and compare the original and sorted arrays?
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.0
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-16 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet