rats 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Mark
1
+ Copyright (c) 2009-2010 Mark G
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -59,6 +59,14 @@ There can be up to a maximum of 36 Sections in a township. The number starts wi
59
59
  North of number 6 and counts up West-to-East until the number 12. It snakes back
60
60
  and forth until it finishes at number 36 in the North-East corner.
61
61
 
62
+ === Half
63
+ a.k.a. Half Section
64
+
65
+ from above example: [= N or = North]
66
+
67
+ The Half Section represents a 1/2 x 1 mile area within the 1x1 mile Section.
68
+ They are identified by "N", "E", "S" and "W".
69
+
62
70
  === Quarter
63
71
  a.k.a. Quarter Section
64
72
 
@@ -91,6 +99,16 @@ fields from multiple string representations of the location.
91
99
  For example, NE 1-2-3 W4 and 40300201NE are both recognized and parsed, representing
92
100
  the same location.
93
101
 
102
+ === Expansion/Division
103
+
104
+ Townships, Sections and Half Sections can be divided into multiple Quarter Sections.
105
+ 1 Half Section = 2 Quarter Sections
106
+ 1 Section = 4 Quarter Sections
107
+ 1 Township = 144 Quarter Sections
108
+
109
+ For example, the Half Section N 1-2-3 W4 has the Quarter Sections NE 1-2-3 W4 and
110
+ NW 1-2-3 W4.
111
+
94
112
  === Display
95
113
 
96
114
  Included is string creation that can create common representations of the
@@ -113,6 +131,13 @@ Read the attributes
113
131
  quarter_section.township
114
132
  quarter_section.range
115
133
  quarter_section.meridian
134
+
135
+ Divide into multiple Quarter Sections
136
+
137
+ half_section = Rats.new("N 1-2-3 W4")
138
+ half_section.is_divisible?
139
+ quarter_sections = half_section.divide
140
+ # quarter_sections == [Rats.new("NE 1-2-3 W4"), Rats.new("NW 1-2-3 W4")]
116
141
 
117
142
  = Information
118
143
 
@@ -143,7 +168,7 @@ cases this assumption breaks down.
143
168
  == Environment
144
169
 
145
170
  This gem was created using:
146
- - ruby 1.9.1-p378, 1.9.2-head
171
+ - ruby 1.9.1-p378, 1.9.2-p0
147
172
  - rspec 1.3.0
148
173
  - rake 0.8.7
149
174
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.1
@@ -70,7 +70,11 @@ module Rats
70
70
  if self.meridian && self.range && self.township
71
71
  if self.section
72
72
  if self.quarter
73
- :quarter
73
+ if Rats::Quarter.half?(self.quarter)
74
+ :half
75
+ else
76
+ :quarter
77
+ end
74
78
  else
75
79
  :section
76
80
  end
@@ -143,7 +147,62 @@ module Rats
143
147
  def to_a
144
148
  [self.quarter, self.section, self.township, self.range, self.meridian].compact
145
149
  end
146
-
150
+
151
+ # can this location be broken down into quarter sections?
152
+ #
153
+ def is_divisible?
154
+ [:half, :section, :township].include?(self.scope)
155
+ end
156
+
157
+ # returns individual quarter sections for a :half_section, :section or :township
158
+ #
159
+ def divide
160
+ return unless self.is_divisible?
161
+ case self.scope
162
+ when :half
163
+ self.divide_half
164
+ when :section
165
+ self.divide_section
166
+ when :township
167
+ self.divide_township
168
+ end
169
+ end
170
+
171
+ def divide_half
172
+ quarters = []
173
+ case self.quarter.to_s.downcase
174
+ when 'n'
175
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'NE')
176
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'NW')
177
+ when 's'
178
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'SE')
179
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'SW')
180
+ when 'e'
181
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'NE')
182
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'SE')
183
+ when 'w'
184
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'NW')
185
+ quarters << Rats.new(self.meridian, self.range, self.township, self.section, 'SW')
186
+ end
187
+ quarters
188
+ end
189
+
190
+ def divide_section(section=nil)
191
+ quarters = []
192
+ ['NE', 'NW', 'SE', 'SW'].each do |quarter|
193
+ quarters << Rats.new(self.meridian, self.range, self.township, section || self.section, quarter)
194
+ end
195
+ quarters
196
+ end
197
+
198
+ def divide_township
199
+ quarters = []
200
+ (1..36).each do |section|
201
+ quarters += divide_section(section)
202
+ end
203
+ quarters
204
+ end
205
+
147
206
  private
148
207
 
149
208
  def parse_string(location)
@@ -162,8 +221,11 @@ module Rats
162
221
  end
163
222
 
164
223
  def parse_description(description)
165
- quarter = description.to_s.scan(/^\D{2}/)
166
- self.quarter = quarter[0].upcase if quarter && quarter.size > 0
224
+ # just skip the case of only a meridian ie: 'W4'
225
+ unless description.to_s.match(/^w\d{1,3}$/i)
226
+ quarter = description.to_s.scan(/^north|^south|^east|^west|^ne|^nw|^se|^sw|^n|^e|^s|^w/i)
227
+ self.quarter = Rats::Quarter.transform(quarter[0]) if quarter && quarter.size > 0
228
+ end
167
229
 
168
230
  numbers = description.to_s.scan(/\d{1,3}/)
169
231
  if numbers
@@ -176,14 +238,14 @@ module Rats
176
238
  end
177
239
 
178
240
  def parse_parcel_id(parcel_id)
179
- result = parcel_id.to_s.scan(/^(\d{1})(\d{2})(\d{3})(\d{2})(\D{2})?/)
241
+ result = parcel_id.to_s.scan(/^(\d{1})(\d{2})(\d{3})(\d{2})(\D{1,2})?/)
180
242
  return unless result && result.size > 0
181
243
  numbers = result.pop.compact
182
244
  self.meridian = numbers.shift.to_i if numbers.size > 0
183
245
  self.range = numbers.shift.to_i if numbers.size > 0
184
246
  self.township = numbers.shift.to_i if numbers.size > 0
185
247
  self.section = numbers.shift.to_i if numbers.size > 0
186
- self.quarter = numbers.shift.to_s if numbers.size > 0
248
+ self.quarter = numbers.shift.to_s.strip if numbers.size > 0
187
249
  true
188
250
  end
189
251
 
@@ -1,7 +1,7 @@
1
1
  module Rats
2
2
  class Quarter < Data
3
3
 
4
- VALID_QUARTERS = [:ne, :nw, :se, :sw]
4
+ VALID_QUARTERS = [:ne, :nw, :se, :sw, :n, :e, :s, :w]
5
5
 
6
6
  def self.padding_width; 2; end
7
7
  def self.padding_value; " "; end
@@ -12,21 +12,48 @@ module Rats
12
12
 
13
13
  def fullname
14
14
  return "" unless self.value
15
- template = "the %s Quarter"
15
+ template = "the %s %s"
16
16
  case self.value.to_s.downcase.to_sym
17
17
  when :ne
18
- sprintf(template, 'Northeast')
18
+ sprintf(template, 'Northeast', 'Quarter')
19
19
  when :se
20
- sprintf(template, 'Southeast')
20
+ sprintf(template, 'Southeast', 'Quarter')
21
21
  when :nw
22
- sprintf(template, 'Northwest')
22
+ sprintf(template, 'Northwest', 'Quarter')
23
23
  when :sw
24
- sprintf(template, 'Southwest')
24
+ sprintf(template, 'Southwest', 'Quarter')
25
+ when :n
26
+ sprintf(template, 'North', 'Half')
27
+ when :e
28
+ sprintf(template, 'East', 'Half')
29
+ when :s
30
+ sprintf(template, 'South', 'Half')
31
+ when :w
32
+ sprintf(template, 'West', 'Half')
25
33
  else
26
34
  ''
27
35
  end
28
36
  end
29
37
 
38
+ def self.half?(value)
39
+ %w(north n south s east e west w).include?(value.to_s.downcase)
40
+ end
41
+
42
+ def self.transform(value)
43
+ v = value.to_s.upcase.strip
44
+ case v
45
+ when 'NORTH'
46
+ v = 'N'
47
+ when 'SOUTH'
48
+ v = 'S'
49
+ when 'EAST'
50
+ v = 'E'
51
+ when 'WEST'
52
+ v = 'W'
53
+ end
54
+ v
55
+ end
56
+
30
57
  private
31
58
 
32
59
  def validate!
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rats}
8
- s.version = "0.2.3"
8
+ s.version = "0.3.1"
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-05-08}
12
+ s.date = %q{2010-09-10}
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 = [
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.homepage = %q{http://github.com/attack/rats}
48
48
  s.rdoc_options = ["--charset=UTF-8"]
49
49
  s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.3.6}
50
+ s.rubygems_version = %q{1.3.7}
51
51
  s.summary = %q{A ruby class to help with using the Alberta Township System}
52
52
  s.test_files = [
53
53
  "spec/data/data_spec.rb",
@@ -64,7 +64,7 @@ Gem::Specification.new do |s|
64
64
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
65
  s.specification_version = 3
66
66
 
67
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
68
  else
69
69
  end
70
70
  else
@@ -12,6 +12,18 @@ describe Rats::Quarter do
12
12
  data.fullname.should == "the Northeast Quarter"
13
13
  end
14
14
 
15
+ it "detects half" do
16
+ Rats::Quarter.half?('NE').should be_false
17
+ Rats::Quarter.half?('N').should be_true
18
+ Rats::Quarter.half?('North').should be_true
19
+ end
20
+
21
+ it "transform input" do
22
+ Rats::Quarter.transform('ne').should == 'NE'
23
+ Rats::Quarter.transform('north').should == 'N'
24
+ Rats::Quarter.transform('n').should == 'N'
25
+ end
26
+
15
27
  describe "boundaries" do
16
28
 
17
29
  it "knows valid data" do
@@ -96,6 +96,26 @@ describe "Rats" do
96
96
  land.scope.should == :quarter
97
97
  end
98
98
 
99
+ it "understands N 1-2-3 W4" do
100
+ land = Rats.new("N 1-2-3 W4")
101
+ land.quarter.should == "N"
102
+ land.section.should == 1
103
+ land.township.should == 2
104
+ land.range.should == 3
105
+ land.meridian.should == 4
106
+ land.scope.should == :half
107
+ end
108
+
109
+ it "understands North 1-2-3 W4" do
110
+ land = Rats.new("North 1-2-3 W4")
111
+ land.quarter.should == "N"
112
+ land.section.should == 1
113
+ land.township.should == 2
114
+ land.range.should == 3
115
+ land.meridian.should == 4
116
+ land.scope.should == :half
117
+ end
118
+
99
119
  it "understands 40300201NE" do
100
120
  land = Rats.new("40300201NE")
101
121
  land.quarter.should == "NE"
@@ -329,6 +349,11 @@ describe "Rats" do
329
349
  land.location(:long).should == "the Northeast Quarter of Section 1, Township 2, Range 3, West of the Fourth Meridian"
330
350
  end
331
351
 
352
+ it "returns the long version with Half" do
353
+ land = Rats.new("N 1-2-3 W4")
354
+ land.location(:long).should == "the North Half of Section 1, Township 2, Range 3, West of the Fourth Meridian"
355
+ end
356
+
332
357
  it "returns the long version with Section" do
333
358
  land = Rats.new("1-2-3 W4")
334
359
  #puts land.inspect
@@ -352,6 +377,16 @@ describe "Rats" do
352
377
  land.scope.should == :quarter
353
378
  end
354
379
 
380
+ it "knows half" do
381
+ land = Rats.new("E 1-2-3 W4")
382
+ land.scope.should == :half
383
+ end
384
+
385
+ it "knows half" do
386
+ land = Rats.new("East 1-2-3 W4")
387
+ land.scope.should == :half
388
+ end
389
+
355
390
  it "knows section" do
356
391
  land = Rats.new("1-2-3 W4")
357
392
  land.scope.should == :section
@@ -398,6 +433,43 @@ describe "Rats" do
398
433
  land = Rats.new("1-2-3 W4")
399
434
  land.to_a.should == [1, 2, 3, 4]
400
435
  end
436
+
437
+ describe "expansion" do
438
+
439
+ it "is divisible" do
440
+ Rats.new("N 1-2-3 W4").is_divisible?.should be_true
441
+ Rats.new("1-2-3 W4").is_divisible?.should be_true
442
+ Rats.new("2-3 W4").is_divisible?.should be_true
443
+ end
444
+
445
+ it "is not divisible" do
446
+ Rats.new("NE 1-2-3 W4").is_divisible?.should be_false
447
+ Rats.new("3 W4").is_divisible?.should be_false
448
+ Rats.new("W4").is_divisible?.should be_false
449
+ end
450
+
451
+ describe "half -> 2 quarters" do
452
+ quarters = Rats.new("N 1-2-3 W4").divide
453
+ quarters.size.should == 2
454
+ quarters.first.quarter.should == 'NE'
455
+ quarters.last.quarter.should == 'NW'
456
+ end
457
+
458
+ describe "section -> 4 quarters" do
459
+ quarters = Rats.new("1-2-3 W4").divide
460
+ quarters.size.should == 4
461
+ quarters[0].quarter.should == 'NE'
462
+ quarters[1].quarter.should == 'NW'
463
+ quarters[2].quarter.should == 'SE'
464
+ quarters[3].quarter.should == 'SW'
465
+ end
466
+
467
+ describe "township -> 144 quarters" do
468
+ quarters = Rats.new("2-3 W4").divide
469
+ quarters.size.should == 144
470
+ end
471
+
472
+ end
401
473
 
402
474
  end
403
475
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
7
  - 3
9
- version: 0.2.3
8
+ - 1
9
+ version: 0.3.1
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-05-08 00:00:00 -06:00
17
+ date: 2010-09-10 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -64,6 +64,7 @@ rdoc_options:
64
64
  require_paths:
65
65
  - lib
66
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
67
68
  requirements:
68
69
  - - ">="
69
70
  - !ruby/object:Gem::Version
@@ -71,6 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
72
  - 0
72
73
  version: "0"
73
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
74
76
  requirements:
75
77
  - - ">="
76
78
  - !ruby/object:Gem::Version
@@ -80,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  requirements: []
81
83
 
82
84
  rubyforge_project:
83
- rubygems_version: 1.3.6
85
+ rubygems_version: 1.3.7
84
86
  signing_key:
85
87
  specification_version: 3
86
88
  summary: A ruby class to help with using the Alberta Township System