rats 0.2.0 → 0.2.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.
- data/README.rdoc +29 -26
- data/VERSION +1 -1
- data/lib/rats/base.rb +54 -10
- data/lib/rats/data/base.rb +19 -3
- data/lib/rats/data/meridian.rb +19 -3
- data/lib/rats/data/quarter.rb +19 -1
- data/lib/rats/data/range.rb +7 -1
- data/lib/rats/data/section.rb +7 -1
- data/lib/rats/data/township.rb +7 -1
- data/rats.gemspec +1 -1
- data/spec/data/data_spec.rb +29 -1
- data/spec/data/meridian_spec.rb +14 -2
- data/spec/data/quarter_spec.rb +12 -5
- data/spec/data/range_spec.rb +11 -4
- data/spec/data/section_spec.rb +11 -4
- data/spec/data/township_spec.rb +11 -4
- data/spec/rats_spec.rb +54 -29
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ a.k.a. Ruby Alberta Township System
|
|
5
5
|
A ruby class to help with using the Alberta Township System. This class will allow
|
6
6
|
you to create and represent townships, sections and quarter sections.
|
7
7
|
|
8
|
-
You may find it amusing that Alberta
|
8
|
+
You may find it amusing that Alberta is Rat-free ... until now.
|
9
9
|
|
10
10
|
== ATS
|
11
11
|
|
@@ -18,7 +18,7 @@ Which can be broken down as follows ...
|
|
18
18
|
|
19
19
|
=== Meridian
|
20
20
|
|
21
|
-
from above example: [W4] West of the 4th Meridian
|
21
|
+
from above example: [= W4] or West of the 4th Meridian
|
22
22
|
|
23
23
|
The Meridian is a constant line running perpendicular to the line of longitude,
|
24
24
|
and increments approx. every 4th line of longitude, from East to West.
|
@@ -28,7 +28,7 @@ Alberta contains 3 of these Meridians, W4 through W6.
|
|
28
28
|
=== Range
|
29
29
|
a.k.a Range Lines
|
30
30
|
|
31
|
-
from above example: [3]
|
31
|
+
from above example: [= 3]
|
32
32
|
|
33
33
|
The Range is the x-axis within the given Meridian. It increases East to West and
|
34
34
|
resets at the next Meridian. Each increase is approx. every 6 miles.
|
@@ -39,9 +39,9 @@ you go North, there is less Ranges from East to West.
|
|
39
39
|
=== Township
|
40
40
|
a.k.a. Township Lines
|
41
41
|
|
42
|
-
from above example: [2]
|
42
|
+
from above example: [= 2]
|
43
43
|
|
44
|
-
The Township is the y-axis
|
44
|
+
The Township is the y-axis within the Meridian. It increases South to North and
|
45
45
|
never resets, running from the Alberta-US border to the Northern border of Alberta.
|
46
46
|
Each increase is approx. every 6 miles.
|
47
47
|
|
@@ -49,16 +49,11 @@ NOTE: The 6x6 mile "square" indicated by the Township (line) + Range (line) +
|
|
49
49
|
Meridian is confusingly called a Township. So you have the Township line and
|
50
50
|
the 6x6 mile Township "square".
|
51
51
|
|
52
|
-
NOTE: Due to the longitude lines getting closer as you go North, there are small
|
53
|
-
correction made South to North which results in a non-uniform stacking of Townships.
|
54
|
-
Therefore you can not assume that going straight North from one Township to another
|
55
|
-
will result in a Township with the same Township-line number.
|
56
|
-
|
57
52
|
=== Section
|
58
53
|
|
59
|
-
from above example: [1]
|
54
|
+
from above example: [= 1]
|
60
55
|
|
61
|
-
The Section represents a
|
56
|
+
The Section represents a 1x1 mile "square" within the 6x6 mile Township.
|
62
57
|
There can be up to a maximum of 36 Sections in a township. The number starts with
|
63
58
|
1 in the South-East corner and travels West to number 6. It then increases to 7
|
64
59
|
North of number 6 and counts up West-to-East until the number 12. It snakes back
|
@@ -67,7 +62,7 @@ and forth until it finishes at number 36 in the North-East corner.
|
|
67
62
|
=== Quarter
|
68
63
|
a.k.a. Quarter Section
|
69
64
|
|
70
|
-
from above example: [NE]
|
65
|
+
from above example: [= NE]
|
71
66
|
|
72
67
|
The Quarter represents a 1/2 x 1/2 mile square within the 1x1 mile Section.
|
73
68
|
There can be 4 Quarters in a Section. They are identified by "NE", "NW", "SE"
|
@@ -81,16 +76,20 @@ the Alberta Township System, at the Quarter, Section or Township level.
|
|
81
76
|
=== Validation
|
82
77
|
|
83
78
|
Included is validations, only allowing you to describe locations that actually
|
84
|
-
exist.
|
79
|
+
exist.
|
85
80
|
|
86
81
|
For example, Range-line 30 is valid for Township-lines 1-18, but not 18-126.
|
87
82
|
|
83
|
+
NOTE: At the moment, invalid quarters within valid sections are not currently
|
84
|
+
identified.
|
85
|
+
|
88
86
|
=== Parsing
|
89
87
|
|
90
88
|
Included is string parsing, allowing you to extract and separate the different
|
91
89
|
fields from multiple string representations of the location.
|
92
90
|
|
93
|
-
For example, NE 1-2-3 W4 and 40300201NE are both recognized and parsed
|
91
|
+
For example, NE 1-2-3 W4 and 40300201NE are both recognized and parsed, representing
|
92
|
+
the same location.
|
94
93
|
|
95
94
|
=== Display
|
96
95
|
|
@@ -99,18 +98,21 @@ location.
|
|
99
98
|
|
100
99
|
= Usage
|
101
100
|
|
102
|
-
|
103
|
-
|
101
|
+
Parse a location
|
102
|
+
|
103
|
+
quarter_section = Rats.new("NE 1-2-3 W4")
|
104
|
+
|
105
|
+
Print the location
|
106
|
+
|
107
|
+
quarter_section.location
|
104
108
|
|
105
|
-
|
106
|
-
quarter_section.location
|
109
|
+
Read the attributes
|
107
110
|
|
108
|
-
|
109
|
-
quarter_section.
|
110
|
-
quarter_section.
|
111
|
-
quarter_section.
|
112
|
-
quarter_section.
|
113
|
-
quarter_section.meridian
|
111
|
+
quarter_section.quarter
|
112
|
+
quarter_section.section
|
113
|
+
quarter_section.township
|
114
|
+
quarter_section.range
|
115
|
+
quarter_section.meridian
|
114
116
|
|
115
117
|
= Information
|
116
118
|
|
@@ -135,7 +137,8 @@ Currently this point has not been reached and this gem is still in development.
|
|
135
137
|
== Assumptions
|
136
138
|
|
137
139
|
As currently written, I assume that within every valid section, all four quarters
|
138
|
-
are valid. I know this to be incorrect
|
140
|
+
are valid. I know this to be incorrect, but I can not correct this until I know which
|
141
|
+
cases this assumption breaks down.
|
139
142
|
|
140
143
|
== Environment
|
141
144
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/rats/base.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Rats
|
2
2
|
class Base
|
3
3
|
|
4
|
+
attr_accessor :errors
|
5
|
+
|
4
6
|
def initialize(*args)
|
5
7
|
return unless args.flatten!
|
6
8
|
@quarter = Rats::Quarter.new
|
@@ -8,6 +10,7 @@ module Rats
|
|
8
10
|
@township = Rats::Township.new
|
9
11
|
@range = Rats::Range.new
|
10
12
|
@meridian = Rats::Meridian.new
|
13
|
+
@errors = {}
|
11
14
|
if args.size == 1
|
12
15
|
parse_string(args.pop)
|
13
16
|
else
|
@@ -39,14 +42,14 @@ module Rats
|
|
39
42
|
def range=(v); @range.v = v; end
|
40
43
|
def meridian=(v); @meridian.v = v; end
|
41
44
|
|
42
|
-
def location(format = :
|
45
|
+
def location(format = :default)
|
43
46
|
case format
|
44
47
|
when :short
|
45
48
|
short_location
|
46
49
|
when :long
|
47
50
|
long_location
|
48
51
|
else
|
49
|
-
|
52
|
+
default_location
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
@@ -60,7 +63,7 @@ module Rats
|
|
60
63
|
end
|
61
64
|
|
62
65
|
def to_s
|
63
|
-
|
66
|
+
default_location
|
64
67
|
end
|
65
68
|
|
66
69
|
def scope
|
@@ -79,21 +82,40 @@ module Rats
|
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
82
|
-
def valid?
|
83
|
-
|
85
|
+
def valid?
|
86
|
+
# check each data field individually
|
87
|
+
[:meridian, :range, :township, :section, :quarter].each do |data|
|
88
|
+
valid = self.send(data.to_s.slice(0)).valid?
|
89
|
+
add_error(data, self.send(data.to_s.slice(0)).error) unless valid
|
90
|
+
end
|
91
|
+
|
92
|
+
# check each field as it relates to others
|
93
|
+
self.exists? unless self.errors.size > 0
|
94
|
+
|
95
|
+
# are we valid?
|
96
|
+
self.errors.size == 0
|
84
97
|
end
|
85
98
|
|
86
99
|
# test that a location actually exists
|
87
100
|
#
|
88
101
|
def exists?
|
89
102
|
# make sure meridian exists
|
90
|
-
|
103
|
+
unless TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian]
|
104
|
+
add_error(:land, 'does not exist')
|
105
|
+
return false
|
106
|
+
end
|
91
107
|
|
92
108
|
# make sure range exists
|
93
|
-
|
109
|
+
unless TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range]
|
110
|
+
add_error(:land, 'does not exist')
|
111
|
+
return false
|
112
|
+
end
|
94
113
|
|
95
114
|
# make sure township exists
|
96
|
-
|
115
|
+
unless TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range][:townships].include?(self.township)
|
116
|
+
add_error(:land, 'does not exist')
|
117
|
+
return false
|
118
|
+
end
|
97
119
|
|
98
120
|
# make sure section exists
|
99
121
|
|
@@ -102,7 +124,12 @@ module Rats
|
|
102
124
|
# NO, now see if this township has valid sections
|
103
125
|
if TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range][:sections].has_key?(self.township)
|
104
126
|
# YES, check further to see that this section is listed
|
105
|
-
|
127
|
+
unless TOWNSHIPS_BY_RANGE_AND_MERIDIAN[self.meridian][self.range][:sections][self.township].include?(self.section)
|
128
|
+
add_error(:land, 'does not exist')
|
129
|
+
return false
|
130
|
+
else
|
131
|
+
return true
|
132
|
+
end
|
106
133
|
else
|
107
134
|
# the township isn't listed, therefore it has all sections
|
108
135
|
return true
|
@@ -169,7 +196,7 @@ module Rats
|
|
169
196
|
end
|
170
197
|
|
171
198
|
|
172
|
-
def
|
199
|
+
def default_location
|
173
200
|
if self.quarter
|
174
201
|
"#{@quarter.to_s} #{[@section.to_s,@township.to_s,@range.to_s].compact.join('-')} #{@meridian.to_s}".strip
|
175
202
|
else
|
@@ -181,5 +208,22 @@ module Rats
|
|
181
208
|
[@quarter.to_p,@section.to_p,@township.to_p,@range.to_p,@meridian.to_p].compact.join('').strip
|
182
209
|
end
|
183
210
|
|
211
|
+
def long_location
|
212
|
+
quarter_section = []
|
213
|
+
quarter_section << self.q.fullname if self.q && self.q.fullname.size > 0
|
214
|
+
quarter_section << self.s.fullname if self.s && self.s.fullname.size > 0
|
215
|
+
parts = []
|
216
|
+
parts << quarter_section.compact.join(' of ') if quarter_section && quarter_section.size > 0
|
217
|
+
parts << self.t.fullname
|
218
|
+
parts << self.r.fullname
|
219
|
+
parts << self.m.fullname
|
220
|
+
parts.compact.join(', ')
|
221
|
+
end
|
222
|
+
|
223
|
+
def add_error(index, the_error)
|
224
|
+
@errors[index] = [] unless @errors.has_key?(index)
|
225
|
+
@errors[index] << the_error
|
226
|
+
end
|
227
|
+
|
184
228
|
end
|
185
229
|
end
|
data/lib/rats/data/base.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
module Rats
|
2
2
|
class Data
|
3
3
|
|
4
|
-
|
4
|
+
ERROR = "not allowed"
|
5
|
+
attr_accessor :value, :raise_errors, :error
|
5
6
|
|
6
|
-
def initialize(value=nil)
|
7
|
+
def initialize(value=nil, raise_errors=false)
|
7
8
|
self.value = value
|
9
|
+
self.raise_errors = raise_errors
|
8
10
|
end
|
9
11
|
|
10
12
|
def nil!; @value = nil; end
|
13
|
+
def raise_errors!; @raise_errors = true; end
|
14
|
+
def raise_errors?; @raise_errors == true; end
|
11
15
|
|
12
16
|
#
|
13
17
|
# READ & WRITE
|
@@ -16,7 +20,7 @@ module Rats
|
|
16
20
|
def value=(value)
|
17
21
|
return unless value
|
18
22
|
@value = self.class.transform(value)
|
19
|
-
raise ArgumentError
|
23
|
+
raise ArgumentError if self.raise_errors? && !self.valid?
|
20
24
|
end
|
21
25
|
alias v= value=
|
22
26
|
alias v value
|
@@ -51,6 +55,18 @@ module Rats
|
|
51
55
|
#
|
52
56
|
|
53
57
|
def valid?
|
58
|
+
set_error! unless valid = validate!
|
59
|
+
valid
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def set_error!
|
66
|
+
self.error = ERROR
|
67
|
+
end
|
68
|
+
|
69
|
+
def validate!
|
54
70
|
true
|
55
71
|
end
|
56
72
|
|
data/lib/rats/data/meridian.rb
CHANGED
@@ -12,11 +12,27 @@ module Rats
|
|
12
12
|
value.to_i > 0 ? value.to_i : nil
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def to_s; "W" + self.value.to_s; end
|
16
|
+
|
17
|
+
def fullname
|
18
|
+
template = "West of the %s Meridian"
|
19
|
+
case @value.to_i
|
20
|
+
when 4
|
21
|
+
sprintf(template, 'Fourth')
|
22
|
+
when 5
|
23
|
+
sprintf(template, 'Fifth')
|
24
|
+
when 6
|
25
|
+
sprintf(template, 'Sixth')
|
26
|
+
else
|
27
|
+
''
|
28
|
+
end
|
17
29
|
end
|
18
30
|
|
19
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def validate!
|
34
|
+
VALID_MERIDIANS.include?(self.value.to_i)
|
35
|
+
end
|
20
36
|
|
21
37
|
end
|
22
38
|
end
|
data/lib/rats/data/quarter.rb
CHANGED
@@ -10,7 +10,25 @@ module Rats
|
|
10
10
|
value.to_s.upcase if value
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def fullname
|
14
|
+
template = "the %s Quarter"
|
15
|
+
case self.value.to_s.downcase.to_sym
|
16
|
+
when :ne
|
17
|
+
sprintf(template, 'Northeast')
|
18
|
+
when :se
|
19
|
+
sprintf(template, 'Southeast')
|
20
|
+
when :nw
|
21
|
+
sprintf(template, 'Northwest')
|
22
|
+
when :sw
|
23
|
+
sprintf(template, 'Southwest')
|
24
|
+
else
|
25
|
+
''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def validate!
|
14
32
|
VALID_QUARTERS.include?(self.value.to_s.downcase.to_sym)
|
15
33
|
end
|
16
34
|
|
data/lib/rats/data/range.rb
CHANGED
@@ -11,12 +11,18 @@ module Rats
|
|
11
11
|
value.to_i > 0 ? value.to_i : nil
|
12
12
|
end
|
13
13
|
|
14
|
+
def fullname
|
15
|
+
"Range #{@value}"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
14
20
|
# NOTE: this does not take into consideration that some ranges do not
|
15
21
|
# exist for some meridians and township (y-axis) values ... but we
|
16
22
|
# would need to know those values, and that is outside the scope
|
17
23
|
# of the Range class.
|
18
24
|
#
|
19
|
-
def
|
25
|
+
def validate!
|
20
26
|
VALID_RANGES.include?(self.value.to_i)
|
21
27
|
end
|
22
28
|
|
data/lib/rats/data/section.rb
CHANGED
data/lib/rats/data/township.rb
CHANGED
@@ -11,12 +11,18 @@ module Rats
|
|
11
11
|
value.to_i > 0 ? value.to_i : nil
|
12
12
|
end
|
13
13
|
|
14
|
+
def fullname
|
15
|
+
"Township #{@value}"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
14
20
|
# NOTE: this does not take into consideration that some townships do not
|
15
21
|
# exist for some meridians and ranges (x-axis) values ... but we
|
16
22
|
# would need to know those values, and that is outside the scope
|
17
23
|
# of the Township class.
|
18
24
|
#
|
19
|
-
def
|
25
|
+
def validate!
|
20
26
|
VALID_TOWNSHIPS.include?(self.value.to_i)
|
21
27
|
end
|
22
28
|
|
data/rats.gemspec
CHANGED
data/spec/data/data_spec.rb
CHANGED
@@ -36,7 +36,6 @@ describe Rats::Data do
|
|
36
36
|
@data.v.should == 1
|
37
37
|
@data.value.should == 1
|
38
38
|
end
|
39
|
-
|
40
39
|
end
|
41
40
|
|
42
41
|
end
|
@@ -48,6 +47,11 @@ describe Rats::Data do
|
|
48
47
|
data.valid?.should be_true
|
49
48
|
end
|
50
49
|
|
50
|
+
it "responds to error" do
|
51
|
+
data = Rats::Data.new
|
52
|
+
data.respond_to?('error').should be_true
|
53
|
+
end
|
54
|
+
|
51
55
|
end
|
52
56
|
|
53
57
|
describe "methods" do
|
@@ -79,4 +83,28 @@ describe Rats::Data do
|
|
79
83
|
|
80
84
|
end
|
81
85
|
|
86
|
+
describe "errors" do
|
87
|
+
|
88
|
+
it "responds to raise_errors!" do
|
89
|
+
data = Rats::Data.new
|
90
|
+
data.respond_to?('raise_errors!').should be_true
|
91
|
+
end
|
92
|
+
|
93
|
+
it "responds to raise_errors?" do
|
94
|
+
data = Rats::Data.new
|
95
|
+
data.respond_to?('raise_errors?').should be_true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "doesn't initially raise errors" do
|
99
|
+
data = Rats::Data.new
|
100
|
+
data.raise_errors?.should be_false
|
101
|
+
end
|
102
|
+
|
103
|
+
it "will raise errors if set" do
|
104
|
+
data = Rats::Data.new(nil, true)
|
105
|
+
data.raise_errors?.should be_true
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
82
110
|
end
|
data/spec/data/meridian_spec.rb
CHANGED
@@ -9,13 +9,20 @@ describe Rats::Meridian do
|
|
9
9
|
|
10
10
|
describe "boundaries" do
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "knows valid data" do
|
13
13
|
data = Rats::Meridian.new(6)
|
14
14
|
data.valid?.should be_true
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "knows invalid data" do
|
18
|
+
data = Rats::Meridian.new(3)
|
19
|
+
data.valid?.should be_false
|
20
|
+
data.error.should == "not allowed"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "raises error with invalid data" do
|
18
24
|
data = Rats::Meridian.new
|
25
|
+
data.raise_errors!
|
19
26
|
lambda { data.value = 3 }.should raise_error(ArgumentError)
|
20
27
|
end
|
21
28
|
|
@@ -43,6 +50,11 @@ describe Rats::Meridian do
|
|
43
50
|
data.v.should == 4
|
44
51
|
end
|
45
52
|
|
53
|
+
it "writes the fullname" do
|
54
|
+
data = Rats::Meridian.new('W4')
|
55
|
+
data.fullname.should == 'West of the Fourth Meridian'
|
56
|
+
end
|
57
|
+
|
46
58
|
describe "transforming" do
|
47
59
|
|
48
60
|
it "accepts integers" do
|
data/spec/data/quarter_spec.rb
CHANGED
@@ -7,16 +7,23 @@ describe Rats::Quarter do
|
|
7
7
|
data.is_a?(Rats::Quarter).should be_true
|
8
8
|
end
|
9
9
|
|
10
|
+
it "returns the full_name" do
|
11
|
+
data = Rats::Quarter.new('NE')
|
12
|
+
data.fullname.should == "the Northeast Quarter"
|
13
|
+
end
|
14
|
+
|
10
15
|
describe "boundaries" do
|
11
16
|
|
12
|
-
it "
|
13
|
-
data = Rats::Quarter.new(
|
17
|
+
it "knows valid data" do
|
18
|
+
data = Rats::Quarter.new('NE')
|
14
19
|
data.valid?.should be_true
|
20
|
+
data.error.should be_nil
|
15
21
|
end
|
16
22
|
|
17
|
-
it "
|
18
|
-
data = Rats::Quarter.new
|
19
|
-
|
23
|
+
it "knows invalid data" do
|
24
|
+
data = Rats::Quarter.new('bad')
|
25
|
+
data.valid?.should be_false
|
26
|
+
data.error.should == "not allowed"
|
20
27
|
end
|
21
28
|
|
22
29
|
end
|
data/spec/data/range_spec.rb
CHANGED
@@ -9,14 +9,16 @@ describe Rats::Range do
|
|
9
9
|
|
10
10
|
describe "boundaries" do
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "knows valid data" do
|
13
13
|
data = Rats::Range.new(6)
|
14
14
|
data.valid?.should be_true
|
15
|
+
data.error.should be_nil
|
15
16
|
end
|
16
17
|
|
17
|
-
it "
|
18
|
-
data = Rats::Range.new
|
19
|
-
|
18
|
+
it "knows invalid data" do
|
19
|
+
data = Rats::Range.new(31)
|
20
|
+
data.valid?.should be_false
|
21
|
+
data.error.should == "not allowed"
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
@@ -38,6 +40,11 @@ describe Rats::Range do
|
|
38
40
|
data.to_s.should == '4'
|
39
41
|
end
|
40
42
|
|
43
|
+
it "writes the fullname" do
|
44
|
+
data = Rats::Range.new('4')
|
45
|
+
data.fullname.should == 'Range 4'
|
46
|
+
end
|
47
|
+
|
41
48
|
describe "transforming" do
|
42
49
|
|
43
50
|
it "accepts integers" do
|
data/spec/data/section_spec.rb
CHANGED
@@ -9,14 +9,16 @@ describe Rats::Section do
|
|
9
9
|
|
10
10
|
describe "boundaries" do
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "knows valid data" do
|
13
13
|
data = Rats::Section.new(6)
|
14
14
|
data.valid?.should be_true
|
15
|
+
data.error.should be_nil
|
15
16
|
end
|
16
17
|
|
17
|
-
it "
|
18
|
-
data = Rats::Section.new
|
19
|
-
|
18
|
+
it "knows invalid data" do
|
19
|
+
data = Rats::Section.new(37)
|
20
|
+
data.valid?.should be_false
|
21
|
+
data.error.should == "not allowed"
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
@@ -38,6 +40,11 @@ describe Rats::Section do
|
|
38
40
|
data.to_s.should == '4'
|
39
41
|
end
|
40
42
|
|
43
|
+
it "writes the fullname" do
|
44
|
+
data = Rats::Section.new('4')
|
45
|
+
data.fullname.should == 'Section 4'
|
46
|
+
end
|
47
|
+
|
41
48
|
describe "transforming" do
|
42
49
|
|
43
50
|
it "accepts integers" do
|
data/spec/data/township_spec.rb
CHANGED
@@ -9,14 +9,16 @@ describe Rats::Township do
|
|
9
9
|
|
10
10
|
describe "boundaries" do
|
11
11
|
|
12
|
-
it "
|
12
|
+
it "knows valid data" do
|
13
13
|
data = Rats::Township.new(6)
|
14
14
|
data.valid?.should be_true
|
15
|
+
data.error.should be_nil
|
15
16
|
end
|
16
17
|
|
17
|
-
it "
|
18
|
-
data = Rats::Township.new
|
19
|
-
|
18
|
+
it "knows invalid data" do
|
19
|
+
data = Rats::Township.new(130)
|
20
|
+
data.valid?.should be_false
|
21
|
+
data.error.should == "not allowed"
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
@@ -38,6 +40,11 @@ describe Rats::Township do
|
|
38
40
|
data.to_s.should == '4'
|
39
41
|
end
|
40
42
|
|
43
|
+
it "writes the fullname" do
|
44
|
+
data = Rats::Township.new('4')
|
45
|
+
data.fullname.should == 'Township 4'
|
46
|
+
end
|
47
|
+
|
41
48
|
describe "transforming" do
|
42
49
|
|
43
50
|
it "accepts integers" do
|
data/spec/rats_spec.rb
CHANGED
@@ -37,7 +37,6 @@ describe "Rats" do
|
|
37
37
|
|
38
38
|
it "writes meridian" do
|
39
39
|
@land.meridian = 4
|
40
|
-
#@land.meridian.should == "W4"
|
41
40
|
@land.meridian.should == 4
|
42
41
|
end
|
43
42
|
|
@@ -53,7 +52,6 @@ describe "Rats" do
|
|
53
52
|
land.section.should == 1
|
54
53
|
land.township.should == 2
|
55
54
|
land.range.should == 3
|
56
|
-
#land.meridian.should == "W4"
|
57
55
|
land.meridian.should == 4
|
58
56
|
end
|
59
57
|
|
@@ -63,7 +61,6 @@ describe "Rats" do
|
|
63
61
|
land.section.should == 1
|
64
62
|
land.township.should == 2
|
65
63
|
land.range.should == 3
|
66
|
-
#land.meridian.should == "W4"
|
67
64
|
land.meridian.should == 4
|
68
65
|
end
|
69
66
|
|
@@ -73,7 +70,6 @@ describe "Rats" do
|
|
73
70
|
land.section.should == 1
|
74
71
|
land.township.should == 2
|
75
72
|
land.range.should == 3
|
76
|
-
#land.meridian.should == "W4"
|
77
73
|
land.meridian.should == 4
|
78
74
|
end
|
79
75
|
|
@@ -83,27 +79,15 @@ describe "Rats" do
|
|
83
79
|
land.section.should == 1
|
84
80
|
land.township.should == 2
|
85
81
|
land.range.should == 3
|
86
|
-
#land.meridian.should == "W4"
|
87
82
|
land.meridian.should == 4
|
88
83
|
end
|
89
84
|
|
90
|
-
# NOT SURE THIS IS USEFUL
|
91
|
-
# it "understands NE01002034" do
|
92
|
-
# land = Rats.new("NE01002034")
|
93
|
-
# land.quarter.should == "NE"
|
94
|
-
# land.section.should == 1
|
95
|
-
# land.township.should == 2
|
96
|
-
# land.range.should == 3
|
97
|
-
# land.meridian.should == "W4"
|
98
|
-
# end
|
99
|
-
|
100
85
|
it "understands 1-2-3 W4" do
|
101
86
|
land = Rats.new("1-2-3 W4")
|
102
87
|
land.quarter.should be_nil
|
103
88
|
land.section.should == 1
|
104
89
|
land.township.should == 2
|
105
90
|
land.range.should == 3
|
106
|
-
#land.meridian.should == "W4"
|
107
91
|
land.meridian.should == 4
|
108
92
|
end
|
109
93
|
|
@@ -113,7 +97,6 @@ describe "Rats" do
|
|
113
97
|
land.section.should be_nil
|
114
98
|
land.township.should == 2
|
115
99
|
land.range.should == 3
|
116
|
-
#land.meridian.should == "W4"
|
117
100
|
land.meridian.should == 4
|
118
101
|
end
|
119
102
|
|
@@ -123,7 +106,6 @@ describe "Rats" do
|
|
123
106
|
land.section.should be_nil
|
124
107
|
land.township.should be_nil
|
125
108
|
land.range.should == 3
|
126
|
-
#land.meridian.should == "W4"
|
127
109
|
land.meridian.should == 4
|
128
110
|
end
|
129
111
|
|
@@ -133,18 +115,15 @@ describe "Rats" do
|
|
133
115
|
land.section.should be_nil
|
134
116
|
land.township.should be_nil
|
135
117
|
land.range.should be_nil
|
136
|
-
#land.meridian.should == "W4"
|
137
118
|
land.meridian.should == 4
|
138
119
|
end
|
139
120
|
|
140
121
|
it "understands individual values" do
|
141
|
-
#land = Rats.new("NE", 1, 2, 3, 4)
|
142
122
|
land = Rats.new(4, 3, 2, 1, "NE")
|
143
123
|
land.quarter.should == "NE"
|
144
124
|
land.section.should == 1
|
145
125
|
land.township.should == 2
|
146
126
|
land.range.should == 3
|
147
|
-
#land.meridian.should == "W4"
|
148
127
|
land.meridian.should == 4
|
149
128
|
end
|
150
129
|
|
@@ -154,7 +133,6 @@ describe "Rats" do
|
|
154
133
|
land.section.should == 1
|
155
134
|
land.township.should == 119
|
156
135
|
land.range.should == 24
|
157
|
-
#land.meridian.should == "W4"
|
158
136
|
land.meridian.should == 4
|
159
137
|
end
|
160
138
|
|
@@ -167,20 +145,17 @@ describe "Rats" do
|
|
167
145
|
land.section.should == 1
|
168
146
|
land.township.should == 2
|
169
147
|
land.range.should == 3
|
170
|
-
#land.meridian.should == "W4"
|
171
148
|
land.meridian.should == 4
|
172
149
|
end
|
173
150
|
|
174
151
|
it "using location and individual values" do
|
175
152
|
land = Rats.new
|
176
|
-
#land.location = ["NE", 1, 2, 3, 4]
|
177
153
|
land.location = [4, 3, 2, 1, "NE"]
|
178
154
|
land.quarter.should == "NE"
|
179
155
|
land.section.should == 1
|
180
156
|
land.township.should == 2
|
181
157
|
land.range.should == 3
|
182
158
|
land.meridian.should == 4
|
183
|
-
#land.meridian.to_s.should == "W4"
|
184
159
|
end
|
185
160
|
|
186
161
|
end
|
@@ -223,22 +198,53 @@ describe "Rats" do
|
|
223
198
|
describe "boundaries" do
|
224
199
|
|
225
200
|
it "knows when a township is North of Alberta" do
|
226
|
-
|
201
|
+
land = Rats.new("SE 1-127-1 W4")
|
202
|
+
land.valid?.should be_false
|
203
|
+
land.errors.size.should == 1
|
204
|
+
land.errors.has_key?(:township).should be_true
|
205
|
+
land.errors[:township].first.should == 'not allowed'
|
227
206
|
end
|
228
207
|
|
229
208
|
it "knows when a township is East of Alberta" do
|
230
|
-
|
209
|
+
land = Rats.new("SE 1-1-1 W3")
|
210
|
+
land.valid?.should be_false
|
211
|
+
land.errors.size.should == 1
|
212
|
+
land.errors.has_key?(:meridian).should be_true
|
213
|
+
land.errors[:meridian].first.should == 'not allowed'
|
231
214
|
end
|
232
215
|
|
233
216
|
it "knows when a township is West of Alberta" do
|
234
|
-
|
217
|
+
land = Rats.new("SE 1-1-1 W7")
|
218
|
+
land.valid?.should be_false
|
219
|
+
land.errors.size.should == 1
|
220
|
+
land.errors.has_key?(:meridian).should be_true
|
221
|
+
land.errors[:meridian].first.should == 'not allowed'
|
222
|
+
end
|
223
|
+
|
224
|
+
it "knows when a township has been squeezed out" do
|
225
|
+
land = Rats.new("SE 1-126-25 W4")
|
226
|
+
land.valid?.should be_false
|
227
|
+
land.errors.size.should == 1
|
228
|
+
land.errors.has_key?(:land).should be_true
|
229
|
+
land.errors[:land].first.should == 'does not exist'
|
230
|
+
end
|
231
|
+
|
232
|
+
it "knows when a section has been squeezed out" do
|
233
|
+
land = Rats.new("SE 6-119-24 W4")
|
234
|
+
land.valid?.should be_false
|
235
|
+
land.errors.size.should == 1
|
236
|
+
land.errors.has_key?(:land).should be_true
|
237
|
+
land.errors[:land].first.should == 'does not exist'
|
235
238
|
end
|
236
239
|
|
240
|
+
# it "knows when a quarter has been squeezed out" do
|
241
|
+
# end
|
242
|
+
|
237
243
|
end
|
238
244
|
|
239
245
|
describe "formatting" do
|
240
246
|
|
241
|
-
describe ":
|
247
|
+
describe ":default" do
|
242
248
|
|
243
249
|
it "returns NE 1-2-3 W4" do
|
244
250
|
land = Rats.new("NE 1-2-3 W4")
|
@@ -276,6 +282,25 @@ describe "Rats" do
|
|
276
282
|
|
277
283
|
end
|
278
284
|
|
285
|
+
describe ":long" do
|
286
|
+
|
287
|
+
it "returns the long version with Quarter" do
|
288
|
+
land = Rats.new("NE 1-2-3 W4")
|
289
|
+
land.location(:long).should == "the Northeast Quarter of Section 1, Township 2, Range 3, West of the Fourth Meridian"
|
290
|
+
end
|
291
|
+
|
292
|
+
it "returns the long version with Section" do
|
293
|
+
land = Rats.new("1-2-3 W4")
|
294
|
+
land.location(:long).should == "Section 1, Township 2, Range 3, West of the Fourth Meridian"
|
295
|
+
end
|
296
|
+
|
297
|
+
it "returns the long version with Township" do
|
298
|
+
land = Rats.new("2-3 W4")
|
299
|
+
land.location(:long).should == "Township 2, Range 3, West of the Fourth Meridian"
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
303
|
+
|
279
304
|
end
|
280
305
|
|
281
306
|
describe "scope" do
|