rats 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  a.k.a. Ruby Alberta Township System
4
4
 
5
- A ruby class to help with using the Alberta Township System
5
+ A ruby class to help with using the Alberta Township System. This class will allow
6
+ you to create and represent townships, sections and quarter sections.
6
7
 
7
8
  You may find it amusing that Alberta was Rat-free ... until now.
8
9
 
@@ -96,32 +97,6 @@ For example, NE 1-2-3 W4 and 40300201NE are both recognized and parsed.
96
97
  Included is string creation that can create common representations of the
97
98
  location.
98
99
 
99
- === Traversing
100
-
101
- NOTE: This is experimental and can probably be improved and made more exact.
102
- See 'Assumptions' to see where possible errors may exist.
103
-
104
- In this case, traverse means go North, South, East or West of a given location
105
- and know what the new location is.
106
-
107
- Within a Township you can traverse any direction from:
108
- - quarter to quarter
109
- - quarter to section
110
- - section to section
111
-
112
- When leaving a Township, you can only traverse West and East from:
113
- - quarter to quarter
114
- - quarter to section
115
- - quarter to township
116
- - section to section
117
- - section to township
118
- - township to township
119
-
120
- NOTE: The limitation in traversing from one Township to another is
121
- due to correction lines and the nature that Townships due no run vertical
122
- from North to South. It might be possible to include a way to allow this
123
- but I do not currently need it.
124
-
125
100
  = Usage
126
101
 
127
102
  # parse a location
@@ -137,11 +112,6 @@ quarter_section.township
137
112
  quarter_section.range
138
113
  quarter_section.meridian
139
114
 
140
- # traverse
141
- new_quarter_section = quarter_section.left
142
- new_quarter_section = quarter_section.left.down
143
- new_section = quarter_section.left(:section)
144
-
145
115
  = Information
146
116
 
147
117
  == links
@@ -151,47 +121,26 @@ http://en.wikipedia.org/wiki/Alberta_Township_System
151
121
  == Road Map
152
122
 
153
123
  Future:
154
- - correct assumption #3 (see below)
124
+ - either correct the assumption that all quarters are valid in a valid
125
+ section, or remove validation completely (re: all or none)
155
126
  - add support for Saskatchewan (no timeline, need to find data)
156
127
  - address bugs, if any
157
128
 
158
129
  Except for the above, once this gem is finalized, I do not see future
159
- development happening unless the North-South Township traversing needs
160
- to be addressed or I want to add ATS to other-system conversions
130
+ development happening unless I want to add ATS to other-system conversions
161
131
  (ie: latitude/longitude). Nothing else is planned.
162
132
 
163
133
  Currently this point has not been reached and this gem is still in development.
164
134
 
165
135
  == Assumptions
166
136
 
167
- I make 3 key assumptions.
168
-
169
- The only assumptions made are in respects to traversing. I do assume that
170
- (#1) traversing within a township, that all sections and quarter sections are
171
- perfectly aligned. If this is not correct, it must be pretty close, and
172
- is close enough for my purpose.
173
-
174
- (#2) I also assume that all townships are perfectly aligned from East to West.
175
-
176
- UPDATE: Based on some GPS data I have access to, the range line (x-axis)
177
- doesn't seem to run perfectly straight from East-to-West, but actually drops
178
- a bit South as you go West. I still assume that quarters/sections/townships
179
- are aligned East-to-West, or rather Right-to-Left, they just follow this pattern
180
- of dropping a bit South as you go West. What this means is that the functions
181
- I use to traverse locations are a bit of a lie. The function .east() and .west()
182
- imply that you are traversing East and West, when they are actually slightly askew,
183
- and could be called .east_and_ever_so_slightly_south() and
184
- .west_and_ever_so_slightly_north() ... but I will leave them named as is.
185
-
186
- (#3) Lastly, I assume that within every valid section, all four quarters are valid.
187
- This has been confirmed to be incorrect. I have recently found a way to get this
188
- data but it will take some time to collect it. I will remove this assumption in a
189
- future version.
137
+ As currently written, I assume that within every valid section, all four quarters
138
+ are valid. I know this to be incorrect.
190
139
 
191
140
  == Environment
192
141
 
193
142
  This gem was created using:
194
- - ruby 1.9.1-p378
143
+ - ruby 1.9.1-p378, 1.9.2-head
195
144
  - rspec 1.3.0
196
145
  - rake 0.8.7
197
146
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/rats/base.rb CHANGED
@@ -113,84 +113,6 @@ module Rats
113
113
  end
114
114
  end
115
115
 
116
- def up(level=nil); self.traverse(:up, level); end
117
- def down(level=nil); self.traverse(:down, level); end
118
- def left(level=nil); self.traverse(:left, level); end
119
- def right(level=nil); self.traverse(:right, level); end
120
- alias north up
121
- alias south down
122
- alias west left
123
- alias east right
124
-
125
- # this just walks from location to location in the given direction until
126
- # it finds the next valid location.
127
- #
128
- def traverse(direction, level=nil)
129
- return unless direction
130
-
131
- new_location = self.dup
132
- # change the scope of the traverse
133
- # eg. allow quarter section to traverse to a section
134
- #
135
- case level
136
- when :section
137
- # we are traversing by section, remove quarter
138
- new_location.q.nil!
139
- when :township
140
- # we are traversing by section, remove quarter & section
141
- new_location.q.nil!
142
- new_location.s.nil!
143
- end
144
-
145
- the_scope = new_location.scope
146
- begin
147
- case the_scope
148
- when :quarter
149
- new_location._traverse_quarter(direction)
150
- when :section
151
- new_location._traverse_section(direction)
152
- when :township
153
- new_location._traverse_range(direction)
154
- end
155
- end until new_location.valid?
156
- new_location
157
- end
158
-
159
- def _traverse_quarter(direction)
160
- begin
161
- self.q = self.q.send(direction)
162
- rescue OutOfSection
163
- self.q = self.q.send(direction.to_s + '!')
164
- self._traverse_section(direction)
165
- end
166
- end
167
-
168
- def _traverse_section(direction)
169
- begin
170
- self.s = self.s.send(direction)
171
- rescue OutOfTownship
172
- self.s = self.s.send(direction.to_s + '!')
173
- self._traverse_range(direction)
174
- end
175
- end
176
-
177
- def _traverse_range(direction)
178
- begin
179
- self.r = self.r.send(direction)
180
- rescue OutOfMeridian
181
- self.r = self.r.send(direction.to_s + '!')
182
- self._traverse_meridian(direction)
183
- end
184
- end
185
-
186
- def _traverse_meridian(direction)
187
- begin
188
- self.m = self.m.send(direction)
189
- rescue
190
- raise OutOfAlberta
191
- end
192
- end
193
-
194
116
  def to_a
195
117
  [self.quarter, self.section, self.township, self.range, self.meridian].compact
196
118
  end
@@ -43,32 +43,6 @@ module Rats
43
43
  return nil unless @value
44
44
  self.value.to_s.rjust(self.class.padding_width,self.class.padding_value)
45
45
  end
46
-
47
- #
48
- # TRAVERSING
49
- #
50
- # - it is expected that a specfic data sub-class will define this
51
- #
52
-
53
- def up; traverse(:up); end
54
- def up!; traverse!(:up); end
55
- alias north up
56
- alias north! up!
57
-
58
- def right; traverse(:right); end
59
- def right!; traverse!(:right); end
60
- alias east right
61
- alias east! right!
62
-
63
- def down; traverse(:down); end
64
- def down!; traverse!(:down); end
65
- alias south down
66
- alias south! down!
67
-
68
- def left; traverse(:left); end
69
- def left!; traverse!(:left); end
70
- alias west left
71
- alias west! left!
72
46
 
73
47
  #
74
48
  # VALIDATION
@@ -79,11 +53,6 @@ module Rats
79
53
  def valid?
80
54
  true
81
55
  end
82
-
83
- private
84
-
85
- def traverse(direction); raise NotImplementedError; end
86
- def traverse!(direction); raise NotImplementedError; end
87
56
 
88
57
  end
89
58
  end
@@ -17,27 +17,6 @@ module Rats
17
17
  end
18
18
 
19
19
  def to_s; "W" + self.value.to_s; end
20
-
21
- private
22
-
23
- # as a meridian, we can only safely traverse within alberta
24
-
25
- def traverse(direction)
26
- raise ArgumentError unless self.v
27
- new_value = case direction.downcase.to_sym
28
- when :up
29
- raise IllegalTraverse
30
- when :right
31
- self.v.to_i > VALID_MERIDIANS.min ? self.v.to_i - 1 : nil
32
- when :down
33
- raise IllegalTraverse
34
- when :left
35
- self.v.to_i < VALID_MERIDIANS.max ? self.v.to_i + 1 : nil
36
- end
37
- raise Rats::OutOfAlberta if new_value.nil?
38
- Rats::Meridian.new(new_value)
39
- end
40
- alias traverse! traverse
41
20
 
42
21
  end
43
22
  end
@@ -3,20 +3,6 @@ module Rats
3
3
 
4
4
  VALID_QUARTERS = [:ne, :nw, :se, :sw]
5
5
 
6
- # order: up, right, down, left
7
- UNBOUNDED_QUARTER_MATRIX = {
8
- :se => [:ne, :sw, :ne, :sw],
9
- :sw => [:nw, :se, :nw, :se],
10
- :nw => [:sw, :ne, :sw, :ne],
11
- :ne => [:se, :nw, :se, :nw]
12
- }
13
- BOUNDED_QUARTER_MATRIX = {
14
- :se => [:ne, nil, nil, :sw],
15
- :sw => [:nw, :se, nil, nil],
16
- :nw => [nil, :ne, :sw, nil],
17
- :ne => [nil, nil, :se, :nw]
18
- }
19
-
20
6
  def self.padding_width; 2; end
21
7
  def self.padding_value; " "; end
22
8
 
@@ -27,41 +13,6 @@ module Rats
27
13
  def valid?
28
14
  VALID_QUARTERS.include?(self.value.to_s.downcase.to_sym)
29
15
  end
30
-
31
- private
32
-
33
- # as a quarter, we can only safely traverse within a section
34
-
35
- def traverse(direction)
36
- raise ArgumentError unless self.v
37
- new_value = case direction.downcase.to_sym
38
- when :up
39
- BOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][0]
40
- when :right
41
- BOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][1]
42
- when :down
43
- BOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][2]
44
- when :left
45
- BOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][3]
46
- end
47
- raise Rats::OutOfSection if new_value.nil?
48
- Rats::Quarter.new(new_value)
49
- end
50
-
51
- def traverse!(direction)
52
- raise ArgumentError unless self.v
53
- new_value = case direction.downcase.to_sym
54
- when :up
55
- UNBOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][0]
56
- when :right
57
- UNBOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][1]
58
- when :down
59
- UNBOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][2]
60
- when :left
61
- UNBOUNDED_QUARTER_MATRIX[self.v.to_s.downcase.to_sym][3]
62
- end
63
- Rats::Quarter.new(new_value)
64
- end
65
16
 
66
17
  end
67
18
  end
@@ -14,46 +14,11 @@ module Rats
14
14
  # NOTE: this does not take into consideration that some ranges do not
15
15
  # exist for some meridians and township (y-axis) values ... but we
16
16
  # would need to know those values, and that is outside the scope
17
- # of the Range class. The Base class will handle these cases.
17
+ # of the Range class.
18
18
  #
19
19
  def valid?
20
20
  VALID_RANGES.include?(self.value.to_i)
21
21
  end
22
22
 
23
- private
24
-
25
- # as a range, we can only safely traverse within a meridian
26
-
27
- def traverse(direction)
28
- raise ArgumentError unless self.v
29
- new_value = case direction.downcase.to_sym
30
- when :up
31
- raise IllegalTraverse
32
- when :right
33
- self.v.to_i > VALID_RANGES.min ? self.v.to_i - 1 : nil
34
- when :down
35
- raise IllegalTraverse
36
- when :left
37
- self.v.to_i < VALID_RANGES.max ? self.v.to_i + 1 : nil
38
- end
39
- raise Rats::OutOfMeridian if new_value.nil?
40
- Rats::Range.new(new_value)
41
- end
42
-
43
- def traverse!(direction)
44
- raise ArgumentError unless self.v
45
- new_value = case direction.downcase.to_sym
46
- when :up
47
- raise IllegalTraverse
48
- when :right
49
- self.v.to_i > VALID_RANGES.min ? self.v.to_i - 1 : VALID_RANGES.max
50
- when :down
51
- raise IllegalTraverse
52
- when :left
53
- self.v.to_i < VALID_RANGES.max ? self.v.to_i + 1 : VALID_RANGES.min
54
- end
55
- Rats::Range.new(new_value)
56
- end
57
-
58
23
  end
59
24
  end
@@ -3,84 +3,6 @@ module Rats
3
3
 
4
4
  VALID_SECTIONS = (1..36)
5
5
 
6
- UNBOUNDED_SECTION_MATRIX = {
7
- 1 => [12, 6, nil, 2],
8
- 2 => [11, 1, nil, 3],
9
- 3 => [10, 2, nil, 4],
10
- 4 => [9, 3, nil, 5],
11
- 5 => [8, 4, nil, 6],
12
- 6 => [7, 5, nil, 1],
13
- 7 => [18, 8, 6, 12],
14
- 8 => [17, 9, 5, 7],
15
- 9 => [16, 10, 4, 8],
16
- 10 => [15, 11, 3, 9],
17
- 11 => [14, 12, 2, 10],
18
- 12 => [13, 7, 1, 11],
19
- 13 => [24, 18, 12, 14],
20
- 14 => [23, 13, 11, 15],
21
- 15 => [22, 14, 10, 16],
22
- 16 => [21, 15, 9, 17],
23
- 17 => [20, 16, 8, 18],
24
- 18 => [19, 17, 7, 13],
25
- 19 => [30, 20, 18, 24],
26
- 20 => [29, 21, 17, 19],
27
- 21 => [28, 22, 16, 20],
28
- 22 => [27, 23, 15, 21],
29
- 23 => [26, 24, 14, 22],
30
- 24 => [25, 19, 13, 23],
31
- 25 => [36, 30, 24, 26],
32
- 26 => [35, 25, 23, 27],
33
- 27 => [34, 26, 22, 28],
34
- 28 => [33, 27, 21, 29],
35
- 29 => [32, 28, 20, 30],
36
- 30 => [31, 29, 19, 25],
37
- 31 => [nil, 32, 30, 36],
38
- 32 => [nil, 33, 29, 31],
39
- 33 => [nil, 34, 28, 32],
40
- 34 => [nil, 35, 27, 33],
41
- 35 => [nil, 36, 26, 34],
42
- 36 => [nil, 31, 25, 35],
43
- }
44
-
45
- BOUNDED_SECTION_MATRIX = {
46
- 1 => [12, nil, nil, 2],
47
- 2 => [11, 1, nil, 3],
48
- 3 => [10, 2, nil, 4],
49
- 4 => [9, 3, nil, 5],
50
- 5 => [8, 4, nil, 6],
51
- 6 => [7, 5, nil, nil],
52
- 7 => [18, 8, 6, nil],
53
- 8 => [17, 9, 5, 7],
54
- 9 => [16, 10, 4, 8],
55
- 10 => [15, 11, 3, 9],
56
- 11 => [14, 12, 2, 10],
57
- 12 => [13, nil, 1, 11],
58
- 13 => [24, nil, 12, 14],
59
- 14 => [23, 13, 11, 15],
60
- 15 => [22, 14, 10, 16],
61
- 16 => [21, 15, 9, 17],
62
- 17 => [20, 16, 8, 18],
63
- 18 => [19, 17, 7, nil],
64
- 19 => [30, 20, 18, nil],
65
- 20 => [29, 21, 17, 19],
66
- 21 => [28, 22, 16, 20],
67
- 22 => [27, 23, 15, 21],
68
- 23 => [26, 24, 14, 22],
69
- 24 => [25, nil, 13, 23],
70
- 25 => [36, nil, 24, 26],
71
- 26 => [35, 25, 23, 27],
72
- 27 => [34, 26, 22, 28],
73
- 28 => [33, 27, 21, 29],
74
- 29 => [32, 28, 20, 30],
75
- 30 => [31, 29, 19, nil],
76
- 31 => [nil, 32, 30, nil],
77
- 32 => [nil, 33, 29, 31],
78
- 33 => [nil, 34, 28, 32],
79
- 34 => [nil, 35, 27, 33],
80
- 35 => [nil, 36, 26, 34],
81
- 36 => [nil, nil, 25, 35],
82
- }
83
-
84
6
  def self.padding_width; 2; end
85
7
  def self.padding_value; "0"; end
86
8
 
@@ -89,46 +11,9 @@ module Rats
89
11
  value.to_i > 0 ? value.to_i : nil
90
12
  end
91
13
 
92
-
93
14
  def valid?
94
15
  VALID_SECTIONS.include?(self.value.to_i)
95
16
  end
96
-
97
- private
98
-
99
- # as a section, we can only safely traverse within a township
100
-
101
- def traverse(direction)
102
- raise ArgumentError unless self.v
103
- new_value = case direction.downcase.to_sym
104
- when :up
105
- BOUNDED_SECTION_MATRIX[self.v.to_i][0]
106
- when :right
107
- BOUNDED_SECTION_MATRIX[self.v.to_i][1]
108
- when :down
109
- BOUNDED_SECTION_MATRIX[self.v.to_i][2]
110
- when :left
111
- BOUNDED_SECTION_MATRIX[self.v.to_i][3]
112
- end
113
- raise Rats::OutOfTownship if new_value.nil?
114
- Rats::Section.new(new_value)
115
- end
116
-
117
- def traverse!(direction)
118
- raise ArgumentError unless self.v
119
- new_value = case direction.downcase.to_sym
120
- when :up
121
- UNBOUNDED_SECTION_MATRIX[self.v.to_i][0]
122
- when :right
123
- UNBOUNDED_SECTION_MATRIX[self.v.to_i][1]
124
- when :down
125
- UNBOUNDED_SECTION_MATRIX[self.v.to_i][2]
126
- when :left
127
- UNBOUNDED_SECTION_MATRIX[self.v.to_i][3]
128
- end
129
- raise Rats::IllegalTraverse if new_value.nil?
130
- Rats::Section.new(new_value)
131
- end
132
17
 
133
18
  end
134
19
  end
@@ -14,14 +14,11 @@ module Rats
14
14
  # NOTE: this does not take into consideration that some townships do not
15
15
  # exist for some meridians and ranges (x-axis) values ... but we
16
16
  # would need to know those values, and that is outside the scope
17
- # of the Township class. The Base class will handle these cases.
17
+ # of the Township class.
18
18
  #
19
19
  def valid?
20
20
  VALID_TOWNSHIPS.include?(self.value.to_i)
21
21
  end
22
22
 
23
- def traverse(direction); raise IllegalTraverse; end
24
- alias taverse! traverse
25
-
26
23
  end
27
24
  end
data/lib/rats.rb CHANGED
@@ -13,11 +13,9 @@ module Rats
13
13
  # custom errors
14
14
  #
15
15
  class OutOfBounds < StandardError; end
16
- class OutOfSection < OutOfBounds; end
17
- class OutOfTownship < OutOfBounds; end
18
- class OutOfMeridian < OutOfBounds; end
19
- class OutOfAlberta < OutOfBounds; end
20
-
21
- class IllegalTraverse < StandardError; end
22
-
16
+ #class OutOfSection < OutOfBounds; end
17
+ #class OutOfTownship < OutOfBounds; end
18
+ #class OutOfMeridian < OutOfBounds; end
19
+ #class OutOfAlberta < OutOfBounds; end
20
+
23
21
  end
data/rats.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rats}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark G"]
12
- s.date = %q{2010-04-02}
12
+ s.date = %q{2010-04-13}
13
13
  s.description = %q{A ruby class to help with using the Alberta Township System}
14
14
  s.email = %q{rats@attackcorp.com}
15
15
  s.extra_rdoc_files = [
@@ -79,44 +79,4 @@ describe Rats::Data do
79
79
 
80
80
  end
81
81
 
82
- describe "traversing" do
83
-
84
- before(:each) do
85
- @data = Rats::Data.new
86
- end
87
-
88
- it "stubs left" do
89
- lambda { @data.left }.should raise_error(NotImplementedError)
90
- end
91
-
92
- it "stubs west" do
93
- lambda { @data.west }.should raise_error(NotImplementedError)
94
- end
95
-
96
- it "stubs right" do
97
- lambda { @data.right }.should raise_error(NotImplementedError)
98
- end
99
-
100
- it "stubs east" do
101
- lambda { @data.east }.should raise_error(NotImplementedError)
102
- end
103
-
104
- it "stubs up" do
105
- lambda { @data.up }.should raise_error(NotImplementedError)
106
- end
107
-
108
- it "stubs north" do
109
- lambda { @data.north }.should raise_error(NotImplementedError)
110
- end
111
-
112
- it "stubs down" do
113
- lambda { @data.down }.should raise_error(NotImplementedError)
114
- end
115
-
116
- it "stubs south" do
117
- lambda { @data.south }.should raise_error(NotImplementedError)
118
- end
119
-
120
- end
121
-
122
82
  end
@@ -21,34 +21,6 @@ describe Rats::Meridian do
21
21
 
22
22
  end
23
23
 
24
- describe "traversing" do
25
-
26
- describe "correctly" do
27
-
28
- it "moves up" do
29
- data = Rats::Meridian.new("5")
30
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
31
- end
32
-
33
- it "moves right" do
34
- data = Rats::Meridian.new("5")
35
- data.right.v.should == 4
36
- end
37
-
38
- it "moves down" do
39
- data = Rats::Meridian.new("5")
40
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
41
- end
42
-
43
- it "moves left" do
44
- data = Rats::Meridian.new("5")
45
- data.left.v.should == 6
46
- end
47
-
48
- end
49
-
50
- end
51
-
52
24
  describe "read/write" do
53
25
 
54
26
  it "returns a padded value" do
@@ -21,56 +21,4 @@ describe Rats::Quarter do
21
21
 
22
22
  end
23
23
 
24
- describe "traversing" do
25
-
26
- describe "correctly" do
27
-
28
- it "moves up" do
29
- data = Rats::Quarter.new("SE")
30
- data.up.v.should == "NE"
31
- end
32
-
33
- it "moves right" do
34
- data = Rats::Quarter.new("NW")
35
- data.right.v.should == "NE"
36
- end
37
-
38
- it "moves down" do
39
- data = Rats::Quarter.new("NW")
40
- data.down.v.should == "SW"
41
- end
42
-
43
- it "moves left" do
44
- data = Rats::Quarter.new("NE")
45
- data.left.v.should == "NW"
46
- end
47
-
48
- end
49
-
50
- describe "out of bounds" do
51
-
52
- it "moves up" do
53
- data = Rats::Quarter.new("NE")
54
- lambda { data.up }.should raise_error(Rats::OutOfBounds)
55
- end
56
-
57
- it "moves right" do
58
- data = Rats::Quarter.new("NE")
59
- lambda { data.right }.should raise_error(Rats::OutOfBounds)
60
- end
61
-
62
- it "moves down" do
63
- data = Rats::Quarter.new("SE")
64
- lambda { data.down }.should raise_error(Rats::OutOfBounds)
65
- end
66
-
67
- it "moves left" do
68
- data = Rats::Quarter.new("NW")
69
- lambda { data.left }.should raise_error(Rats::OutOfBounds)
70
- end
71
-
72
- end
73
-
74
- end
75
-
76
24
  end
@@ -21,34 +21,6 @@ describe Rats::Range do
21
21
 
22
22
  end
23
23
 
24
- describe "traversing" do
25
-
26
- describe "correctly" do
27
-
28
- it "moves up" do
29
- data = Rats::Range.new("5")
30
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
31
- end
32
-
33
- it "moves right" do
34
- data = Rats::Range.new("5")
35
- data.right.v.should == 4
36
- end
37
-
38
- it "moves down" do
39
- data = Rats::Range.new("5")
40
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
41
- end
42
-
43
- it "moves left" do
44
- data = Rats::Range.new("5")
45
- data.left.v.should == 6
46
- end
47
-
48
- end
49
-
50
- end
51
-
52
24
  describe "read/write" do
53
25
 
54
26
  it "returns a padded value" do
@@ -21,58 +21,6 @@ describe Rats::Section do
21
21
 
22
22
  end
23
23
 
24
- describe "traversing" do
25
-
26
- describe "correctly" do
27
-
28
- it "moves up" do
29
- data = Rats::Section.new("6")
30
- data.up.v.should == 7
31
- end
32
-
33
- it "moves right" do
34
- data = Rats::Section.new("6")
35
- data.right.v.should == 5
36
- end
37
-
38
- it "moves down" do
39
- data = Rats::Section.new("7")
40
- data.down.v.should == 6
41
- end
42
-
43
- it "moves left" do
44
- data = Rats::Section.new("1")
45
- data.left.v.should == 2
46
- end
47
-
48
- end
49
-
50
- describe "out of bounds" do
51
-
52
- it "moves up" do
53
- data = Rats::Section.new("36")
54
- lambda { data.up }.should raise_error(Rats::OutOfBounds)
55
- end
56
-
57
- it "moves right" do
58
- data = Rats::Section.new("1")
59
- lambda { data.right }.should raise_error(Rats::OutOfBounds)
60
- end
61
-
62
- it "moves down" do
63
- data = Rats::Section.new("1")
64
- lambda { data.down }.should raise_error(Rats::OutOfBounds)
65
- end
66
-
67
- it "moves left" do
68
- data = Rats::Section.new("6")
69
- lambda { data.left }.should raise_error(Rats::OutOfBounds)
70
- end
71
-
72
- end
73
-
74
- end
75
-
76
24
  describe "read/write" do
77
25
 
78
26
  it "returns a padded value" do
@@ -21,34 +21,6 @@ describe Rats::Township do
21
21
 
22
22
  end
23
23
 
24
- describe "traversing" do
25
-
26
- describe "correctly" do
27
-
28
- it "moves up" do
29
- data = Rats::Township.new("5")
30
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
31
- end
32
-
33
- it "moves right" do
34
- data = Rats::Township.new("5")
35
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
36
- end
37
-
38
- it "moves down" do
39
- data = Rats::Township.new("5")
40
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
41
- end
42
-
43
- it "moves left" do
44
- data = Rats::Township.new("5")
45
- lambda { data.up }.should raise_error(Rats::IllegalTraverse)
46
- end
47
-
48
- end
49
-
50
- end
51
-
52
24
  describe "read/write" do
53
25
 
54
26
  it "returns a padded value" do
data/spec/rats_spec.rb CHANGED
@@ -236,362 +236,6 @@ describe "Rats" do
236
236
 
237
237
  end
238
238
 
239
- describe "taversing" do
240
-
241
- describe "from quarter to quarter" do
242
-
243
- describe "within a township" do
244
-
245
- describe "within a section" do
246
-
247
- it "knows what is up (north)" do
248
- land = Rats.new("SE 1-2-3 W4")
249
- land.up.location.should == "NE 1-2-3 W4"
250
- end
251
-
252
- it "knows what is down (south)" do
253
- land = Rats.new("NE 1-2-3 W4")
254
- land.down.location.should == "SE 1-2-3 W4"
255
- end
256
-
257
- it "knows what is left (west)" do
258
- land = Rats.new("SE 1-2-3 W4")
259
- land.left.location.should == "SW 1-2-3 W4"
260
- end
261
-
262
- it "knows what is right (east)" do
263
- land = Rats.new("SW 1-2-3 W4")
264
- land.right.location.should == "SE 1-2-3 W4"
265
- end
266
-
267
- end
268
-
269
- describe "outside a section" do
270
-
271
- it "knows what is up (north)" do
272
- land = Rats.new("NE 1-2-3 W4")
273
- land.up.location.should == "SE 12-2-3 W4"
274
- end
275
-
276
- it "knows what is down (south)" do
277
- land = Rats.new("SE 12-2-3 W4")
278
- land.down.location.should == "NE 1-2-3 W4"
279
- end
280
-
281
- it "knows what is left (west)" do
282
- land = Rats.new("SW 1-2-3 W4")
283
- land.left.location.should == "SE 2-2-3 W4"
284
- end
285
-
286
- it "knows what is right (east)" do
287
- land = Rats.new("NE 2-2-3 W4")
288
- land.right.location.should == "NW 1-2-3 W4"
289
- end
290
-
291
- end
292
-
293
- end
294
-
295
- describe "outside a township (which implies outside a section)" do
296
-
297
- # townships do not line up North to South, so you can't know
298
- # what township/section/quarter is above another when you
299
- # leave a township
300
-
301
- it "knows it can't go up (north)" do
302
- land = Rats.new("NE 36-2-3 W4")
303
- lambda { land.up }.should raise_error(IllegalTraverse)
304
- end
305
-
306
- it "knows it can't go down (south)" do
307
- land = Rats.new("SE 1-2-3 W4")
308
- lambda { land.down }.should raise_error(IllegalTraverse)
309
- end
310
-
311
- it "knows what is left (west)" do
312
- land = Rats.new("SW 6-2-3 W4")
313
- land.left.location.should == "SE 1-2-4 W4"
314
- end
315
-
316
- it "knows what is right (east)" do
317
- land = Rats.new("NE 1-2-3 W4")
318
- land.right.location.should == "NW 6-2-2 W4"
319
- end
320
-
321
- end
322
-
323
- describe "outside a meridian (which implies outside a section and township)" do
324
-
325
- # NOTE: you cannot leave a meridian by going North or South
326
-
327
- it "knows what is left (west)" do
328
- land = Rats.new("SW 6-2-30 W4")
329
- land.left.location.should == "SE 1-2-1 W5"
330
- end
331
-
332
- it "knows what is right (east)" do
333
- land = Rats.new("NE 1-2-1 W5")
334
- land.right.location.should == "NW 6-2-30 W4"
335
- end
336
-
337
- end
338
-
339
- describe "with complicated gaps in valid quarter sections" do
340
-
341
- # this is the ultimate test(s). Can we traverse to the next quarter
342
- # when the normal rules do not apply for what is next?
343
-
344
- def skip(q,s,t,m)
345
- skips = (q + s*2 + t*6*2 + m*30*6*2) || 0
346
- skips -= 1 unless skips == 0
347
- answers = ([false]*skips + [true]).to_a
348
-
349
- Rats::Base.any_instance.stubs(:valid?).returns(*answers)
350
- end
351
-
352
- it "should skip sections going left (west)" do
353
- skip(1,0,0,0)
354
-
355
- land = Rats.new("NE 1-1-2 W4")
356
- new_land = land.left
357
- new_land.location.should == "NW 1-1-2 W4"
358
- end
359
-
360
- it "should skip sections going left (west)" do
361
- skip(0,1,0,0)
362
-
363
- land = Rats.new("NW 1-1-2 W4")
364
- new_land = land.left
365
- new_land.location.should == "NW 2-1-2 W4"
366
- end
367
-
368
- it "should skip sections going left (west)" do
369
- skip(0,0,1,0)
370
-
371
- land = Rats.new("NW 1-1-2 W4")
372
- new_land = land.left
373
- new_land.location.should == "NW 1-1-3 W4"
374
- end
375
-
376
- it "should skip sections going left (west)" do
377
- skip(0,0,0,1)
378
-
379
- land = Rats.new("NW 1-1-2 W4")
380
- new_land = land.left
381
- new_land.location.should == "NW 1-1-2 W5"
382
- end
383
-
384
- end
385
-
386
- end
387
-
388
- describe "from section to section" do
389
-
390
- describe "within a township" do
391
-
392
- it "knows what is up (north)" do
393
- land = Rats.new("1-2-3 W4")
394
- land.up.location.should == "12-2-3 W4"
395
- end
396
-
397
- it "knows what is down (south)" do
398
- land = Rats.new("7-2-3 W4")
399
- land.down.location.should == "6-2-3 W4"
400
- end
401
-
402
- it "knows what is left (west)" do
403
- land = Rats.new("12-2-3 W4")
404
- land.left.location.should == "11-2-3 W4"
405
- end
406
-
407
- it "knows what is right (east)" do
408
- land = Rats.new("6-2-3 W4")
409
- land.right.location.should == "5-2-3 W4"
410
- end
411
-
412
- end
413
-
414
- describe "outside a township" do
415
-
416
- # townships do not line up North to South, so you can't know
417
- # what township/section/quarter is above another when you
418
- # leave a township
419
-
420
- it "knows it can't go up (north)" do
421
- land = Rats.new("35-2-3 W4")
422
- lambda { land.up }.should raise_error(IllegalTraverse)
423
- end
424
-
425
- it "knows it can't go down (south)" do
426
- land = Rats.new("1-2-3 W4")
427
- lambda { land.down }.should raise_error(IllegalTraverse)
428
- end
429
-
430
- it "knows what is left (west)" do
431
- land = Rats.new("6-2-3 W4")
432
- land.left.location.should == "1-2-4 W4"
433
- end
434
-
435
- it "knows what is right (east)" do
436
- land = Rats.new("1-2-3 W4")
437
- land.right.location.should == "6-2-2 W4"
438
- end
439
-
440
- end
441
-
442
- end
443
-
444
- describe "from township to township" do
445
-
446
- describe "within a meridian" do
447
-
448
- it "knows it can't go up (north)" do
449
- land = Rats.new("2-3 W4")
450
- lambda { land.up }.should raise_error(IllegalTraverse)
451
- end
452
-
453
- it "knows it can't go down (south)" do
454
- land = Rats.new("2-3 W4")
455
- lambda { land.down }.should raise_error(IllegalTraverse)
456
- end
457
-
458
- it "knows what is left (west)" do
459
- land = Rats.new("2-3 W4")
460
- land.left.location.should == "2-4 W4"
461
- end
462
-
463
- it "knows what is right (east)" do
464
- land = Rats.new("2-3 W4")
465
- land.right.location.should == "2-2 W4"
466
- end
467
-
468
- end
469
-
470
- end
471
-
472
- describe "from quarter to section" do
473
-
474
- describe "within a township" do
475
-
476
- it "knows what is up (north)" do
477
- land = Rats.new("SE 1-2-3 W4")
478
- land.up(:section).location.should == "12-2-3 W4"
479
- end
480
-
481
- it "knows what is down (south)" do
482
- land = Rats.new("NE 7-2-3 W4")
483
- land.down(:section).location.should == "6-2-3 W4"
484
- end
485
-
486
- it "knows what is left (west)" do
487
- land = Rats.new("NE 12-2-3 W4")
488
- land.left(:section).location.should == "11-2-3 W4"
489
- end
490
-
491
- it "knows what is right (east)" do
492
- land = Rats.new("NW 6-2-3 W4")
493
- land.right(:section).location.should == "5-2-3 W4"
494
- end
495
-
496
- end
497
-
498
- describe "outside a township" do
499
-
500
- # townships do not line up North to South, so you can't know
501
- # what township/section/quarter is above another when you
502
- # leave a township
503
-
504
- it "knows it can't go up (north)" do
505
- land = Rats.new("SE 35-2-3 W4")
506
- lambda { land.up(:section) }.should raise_error(IllegalTraverse)
507
- end
508
-
509
- it "knows it can't go down (south)" do
510
- land = Rats.new("NE 1-2-3 W4")
511
- lambda { land.down(:section) }.should raise_error(IllegalTraverse)
512
- end
513
-
514
- it "knows what is left (west)" do
515
- land = Rats.new("NE 6-2-3 W4")
516
- land.left(:section).location.should == "1-2-4 W4"
517
- end
518
-
519
- it "knows what is right (east)" do
520
- land = Rats.new("NW 1-2-3 W4")
521
- land.right(:section).location.should == "6-2-2 W4"
522
- end
523
-
524
- end
525
-
526
- end
527
-
528
- describe "from quarter to township" do
529
-
530
- describe "within a meridian" do
531
-
532
- it "knows it can't go up (north)" do
533
- land = Rats.new("NE 1-2-3 W4")
534
- lambda { land.up(:township) }.should raise_error(IllegalTraverse)
535
- end
536
-
537
- it "knows it can't go down (south)" do
538
- land = Rats.new("NE 1-2-3 W4")
539
- lambda { land.down(:township) }.should raise_error(IllegalTraverse)
540
- end
541
-
542
- it "knows what is left (west)" do
543
- land = Rats.new("NE 1-2-3 W4")
544
- land.left(:township).location.should == "2-4 W4"
545
- end
546
-
547
- it "knows what is right (east)" do
548
- land = Rats.new("NE 1-2-3 W4")
549
- land.right(:township).location.should == "2-2 W4"
550
- end
551
-
552
- end
553
-
554
- end
555
-
556
- describe "from section to township" do
557
-
558
- describe "within a meridian" do
559
-
560
- it "knows it can't go up (north)" do
561
- land = Rats.new("1-2-3 W4")
562
- lambda { land.up(:township) }.should raise_error(IllegalTraverse)
563
- end
564
-
565
- it "knows it can't go down (south)" do
566
- land = Rats.new("1-2-3 W4")
567
- lambda { land.down(:township) }.should raise_error(IllegalTraverse)
568
- end
569
-
570
- it "knows what is left (west)" do
571
- land = Rats.new("1-2-3 W4")
572
- land.left(:township).location.should == "2-4 W4"
573
- end
574
-
575
- it "knows what is right (east)" do
576
- land = Rats.new("1-2-3 W4")
577
- land.right(:township).location.should == "2-2 W4"
578
- end
579
-
580
- end
581
-
582
- end
583
-
584
- describe "chaining" do
585
-
586
- it "allows chaining of traversing" do
587
- land = Rats.new("NE 1-2-3 W4")
588
- land.up.down.left.right.location.should == "NE 1-2-3 W4"
589
- end
590
-
591
- end
592
-
593
- end
594
-
595
239
  describe "formatting" do
596
240
 
597
241
  describe ":long" do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark G
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-02 00:00:00 -04:00
17
+ date: 2010-04-13 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20