rats 0.4.1 → 0.5.0

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.
@@ -1,13 +1,13 @@
1
1
  module Rats
2
2
  class Base
3
-
3
+
4
4
  # TODO: this data needs to be updated to list the sections where not
5
5
  # all quarters are valid, and list whoch ones are.
6
-
6
+
7
7
  # this array doesn't define what is valid, but trys to define what
8
8
  # combinations of meridian/range/township/section exist
9
9
  #
10
-
10
+
11
11
  # format
12
12
  # VALID_MERIDIAN => {
13
13
  # # NOTE: any RANGE not listed here, does not exist
@@ -25,7 +25,7 @@ module Rats
25
25
  # VALID_SECTION => ARRAY_OF_VALID_QUARTERS
26
26
  # }
27
27
  # }
28
-
28
+
29
29
  # proposed format (allows for quarters to be listed)
30
30
  #
31
31
  # TOWNSHIPS_BY_RANGE_AND_MERIDIAN = {
@@ -60,7 +60,7 @@ module Rats
60
60
  # }
61
61
  # }
62
62
  # }
63
-
63
+
64
64
  TOWNSHIPS_BY_RANGE_AND_MERIDIAN = {
65
65
  4 => {
66
66
  1 => { :townships => 1..126 },
@@ -631,6 +631,6 @@ module Rats
631
631
  },
632
632
  }
633
633
  }
634
-
634
+
635
635
  end
636
- end
636
+ end
@@ -1,10 +1,6 @@
1
- $:.unshift(File.dirname(__FILE__))
2
-
3
- # data
4
- #
5
- require 'data/base'
6
- require 'data/quarter'
7
- require 'data/section'
8
- require 'data/township'
9
- require 'data/range'
10
- require 'data/meridian'
1
+ require_relative 'data/base'
2
+ require_relative 'data/quarter'
3
+ require_relative 'data/section'
4
+ require_relative 'data/township'
5
+ require_relative 'data/range'
6
+ require_relative 'data/meridian'
@@ -1,22 +1,22 @@
1
1
  module Rats
2
2
  class Data
3
-
3
+
4
4
  ERROR = "not allowed"
5
5
  attr_accessor :value, :raise_errors, :error
6
-
6
+
7
7
  def initialize(value=nil, raise_errors=false)
8
8
  self.value = value
9
9
  self.raise_errors = raise_errors
10
10
  end
11
-
11
+
12
12
  def nil!; @value = nil; end
13
13
  def raise_errors!; @raise_errors = true; end
14
14
  def raise_errors?; @raise_errors == true; end
15
-
15
+
16
16
  #
17
17
  # READ & WRITE
18
18
  #
19
-
19
+
20
20
  def value=(value)
21
21
  return unless value
22
22
  @value = self.class.transform(value)
@@ -24,15 +24,15 @@ module Rats
24
24
  end
25
25
  alias v= value=
26
26
  alias v value
27
-
27
+
28
28
  # optional: override this in a sub-class
29
29
  #
30
30
  def self.transform(value); value; end
31
-
31
+
32
32
  #
33
33
  # DISPLAY
34
34
  #
35
-
35
+
36
36
  def to_s
37
37
  return nil unless @value
38
38
  self.value.to_s
@@ -42,18 +42,18 @@ module Rats
42
42
  #
43
43
  def self.padding_width; 1; end
44
44
  def self.padding_value; " "; end
45
-
45
+
46
46
  def to_p
47
47
  return nil unless @value
48
48
  self.value.to_s.rjust(self.class.padding_width,self.class.padding_value)
49
49
  end
50
-
50
+
51
51
  #
52
52
  # VALIDATION
53
53
  #
54
54
  # - it is expected that a specfic data sub-class will re-define this
55
55
  #
56
-
56
+
57
57
  def valid?
58
58
  set_error! unless valid = validate!
59
59
  valid
@@ -65,10 +65,10 @@ module Rats
65
65
  def set_error!
66
66
  self.error = ERROR
67
67
  end
68
-
68
+
69
69
  def validate!
70
70
  true
71
71
  end
72
-
72
+
73
73
  end
74
- end
74
+ end
@@ -1,19 +1,19 @@
1
1
  module Rats
2
2
  class Meridian < Data
3
-
3
+
4
4
  VALID_MERIDIANS = (4..6)
5
-
5
+
6
6
  def self.padding_width; 1; end
7
7
  def self.padding_value; " "; end
8
-
8
+
9
9
  def self.transform(value)
10
10
  return unless value
11
11
  value = value.to_s.upcase.reverse.chomp('W').reverse
12
12
  value.to_i > 0 ? value.to_i : nil
13
13
  end
14
-
14
+
15
15
  def to_s; "W" + self.value.to_s; end
16
-
16
+
17
17
  def fullname
18
18
  template = "West of the %s Meridian"
19
19
  case @value.to_i
@@ -27,12 +27,12 @@ module Rats
27
27
  ''
28
28
  end
29
29
  end
30
-
30
+
31
31
  private
32
-
32
+
33
33
  def validate!
34
34
  VALID_MERIDIANS.include?(self.value.to_i)
35
35
  end
36
36
 
37
37
  end
38
- end
38
+ end
@@ -1,6 +1,6 @@
1
1
  module Rats
2
2
  class Quarter < Data
3
-
3
+
4
4
  VALID_QUARTERS = [
5
5
  :all,
6
6
  :nse, :nsw, :enw, :esw, :sne, :snw, :wse, :wne,
@@ -8,14 +8,14 @@ module Rats
8
8
  :ne, :nw, :se, :sw,
9
9
  :n, :e, :s, :w
10
10
  ]
11
-
11
+
12
12
  def self.padding_width; 2; end
13
13
  def self.padding_value; " "; end
14
-
14
+
15
15
  def self.transform(value)
16
16
  value.to_s.upcase if value
17
17
  end
18
-
18
+
19
19
  def fullname
20
20
  return "" unless self.value
21
21
  template = "the %s %s"
@@ -74,11 +74,11 @@ module Rats
74
74
  ''
75
75
  end
76
76
  end
77
-
77
+
78
78
  def self.half?(value)
79
79
  %w(all nse nsw enw esw sne snw wse wne nws nes sen swn nwe new sew swe north n south s east e west w).include?(value.to_s.downcase)
80
80
  end
81
-
81
+
82
82
  def self.transform(value)
83
83
  v = value.to_s.upcase.strip
84
84
  case v
@@ -93,13 +93,13 @@ module Rats
93
93
  end
94
94
  v
95
95
  end
96
-
96
+
97
97
  private
98
-
98
+
99
99
  def validate!
100
100
  return unless self.value
101
101
  VALID_QUARTERS.include?(self.value.to_s.downcase.to_sym)
102
102
  end
103
-
103
+
104
104
  end
105
- end
105
+ end
@@ -1,22 +1,22 @@
1
1
  module Rats
2
2
  class Range < Data
3
-
3
+
4
4
  VALID_RANGES = (1..30)
5
-
5
+
6
6
  def self.padding_width; 2; end
7
7
  def self.padding_value; "0"; end
8
-
8
+
9
9
  def self.transform(value)
10
10
  return unless value
11
11
  value.to_i > 0 ? value.to_i : nil
12
12
  end
13
-
13
+
14
14
  def fullname
15
15
  "Range #{@value}"
16
16
  end
17
-
17
+
18
18
  private
19
-
19
+
20
20
  # NOTE: this does not take into consideration that some ranges do not
21
21
  # exist for some meridians and township (y-axis) values ... but we
22
22
  # would need to know those values, and that is outside the scope
@@ -25,6 +25,6 @@ module Rats
25
25
  def validate!
26
26
  VALID_RANGES.include?(self.value.to_i)
27
27
  end
28
-
28
+
29
29
  end
30
- end
30
+ end
@@ -1,25 +1,25 @@
1
1
  module Rats
2
2
  class Section < Data
3
-
3
+
4
4
  VALID_SECTIONS = (1..36)
5
-
5
+
6
6
  def self.padding_width; 2; end
7
7
  def self.padding_value; "0"; end
8
-
8
+
9
9
  def self.transform(value)
10
10
  return unless value
11
11
  value.to_i > 0 ? value.to_i : nil
12
12
  end
13
-
13
+
14
14
  def fullname
15
15
  @value && @value.to_i > 0 ? "Section #{@value}" : ''
16
16
  end
17
-
17
+
18
18
  private
19
-
19
+
20
20
  def validate!
21
21
  VALID_SECTIONS.include?(self.value.to_i)
22
22
  end
23
-
23
+
24
24
  end
25
- end
25
+ end
@@ -1,22 +1,22 @@
1
1
  module Rats
2
2
  class Township < Data
3
-
3
+
4
4
  VALID_TOWNSHIPS = (1..126)
5
-
5
+
6
6
  def self.padding_width; 3; end
7
7
  def self.padding_value; "0"; end
8
-
8
+
9
9
  def self.transform(value)
10
10
  return unless value
11
11
  value.to_i > 0 ? value.to_i : nil
12
12
  end
13
-
13
+
14
14
  def fullname
15
15
  "Township #{@value}"
16
16
  end
17
-
17
+
18
18
  private
19
-
19
+
20
20
  # NOTE: this does not take into consideration that some townships do not
21
21
  # exist for some meridians and ranges (x-axis) values ... but we
22
22
  # would need to know those values, and that is outside the scope
@@ -25,6 +25,6 @@ module Rats
25
25
  def validate!
26
26
  VALID_TOWNSHIPS.include?(self.value.to_i)
27
27
  end
28
-
28
+
29
29
  end
30
- end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Rats
2
+ VERSION = '0.5.0'
3
+ end
@@ -1,73 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'rats/version'
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{rats}
8
- s.version = "0.4.1"
6
+ s.name = 'rats'
7
+ s.version = Rats::VERSION
8
+ s.authors = ['Mark Gangl']
9
+ s.email = ['mark@attackcorp.com']
10
+ s.description = 'A ruby class to help with using the Alberta Township System'
11
+ s.summary = s.description
12
+ s.homepage = 'http://github.com/attack/rats'
13
+ s.license = 'MIT'
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Mark G"]
12
- s.date = %q{2011-01-26}
13
- s.description = %q{A ruby class to help with using the Alberta Township System}
14
- s.email = %q{rats@attackcorp.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/rats.rb",
27
- "lib/rats/base.rb",
28
- "lib/rats/boundaries.rb",
29
- "lib/rats/data.rb",
30
- "lib/rats/data/base.rb",
31
- "lib/rats/data/meridian.rb",
32
- "lib/rats/data/quarter.rb",
33
- "lib/rats/data/range.rb",
34
- "lib/rats/data/section.rb",
35
- "lib/rats/data/township.rb",
36
- "rats.gemspec",
37
- "spec/data/data_spec.rb",
38
- "spec/data/meridian_spec.rb",
39
- "spec/data/quarter_spec.rb",
40
- "spec/data/range_spec.rb",
41
- "spec/data/section_spec.rb",
42
- "spec/data/township_spec.rb",
43
- "spec/rats_spec.rb",
44
- "spec/spec.opts",
45
- "spec/spec_helper.rb"
46
- ]
47
- s.homepage = %q{http://github.com/attack/rats}
48
- s.rdoc_options = ["--charset=UTF-8"]
49
- s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.3.5}
51
- s.summary = %q{A ruby class to help with using the Alberta Township System}
52
- s.test_files = [
53
- "spec/data/data_spec.rb",
54
- "spec/data/meridian_spec.rb",
55
- "spec/data/quarter_spec.rb",
56
- "spec/data/range_spec.rb",
57
- "spec/data/section_spec.rb",
58
- "spec/data/township_spec.rb",
59
- "spec/rats_spec.rb",
60
- "spec/spec_helper.rb"
61
- ]
15
+ s.platform = Gem::Platform::RUBY
16
+ s.required_ruby_version = '>= 1.9.2'
62
17
 
63
- if s.respond_to? :specification_version then
64
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
- s.specification_version = 3
18
+ s.files = `git ls-files`.split($/)
19
+ s.test_files = s.files.grep(%r{^spec/})
20
+ s.require_paths = ['lib']
66
21
 
67
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
68
- else
69
- end
70
- else
71
- end
22
+ s.add_development_dependency 'bundler'
72
23
  end
73
24
 
@@ -1,110 +1,95 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require_relative '../spec_helper'
2
2
 
3
3
  describe Rats::Data do
4
-
5
4
  it "initializes" do
6
5
  data = Rats::Data.new
7
6
  data.is_a?(Rats::Data).should be_true
8
7
  end
9
-
8
+
10
9
  describe "attributes" do
11
-
12
- before(:each) do
13
- @data = Rats::Data.new
14
- end
15
-
10
+ let(:data) { Rats::Data.new }
11
+
16
12
  describe "writing and reading" do
17
-
18
13
  it "writes string" do
19
- @data.value = "1"
20
- @data.value.should == "1"
14
+ data.value = "1"
15
+ data.value.should == "1"
21
16
  end
22
-
17
+
23
18
  it "writes integer" do
24
- @data.value = 1
25
- @data.value.should == 1
19
+ data.value = 1
20
+ data.value.should == 1
26
21
  end
27
-
22
+
28
23
  it "writes string using alternate" do
29
- @data.v = "1"
30
- @data.v.should == "1"
31
- @data.value.should == "1"
24
+ data.v = "1"
25
+ data.v.should == "1"
26
+ data.value.should == "1"
32
27
  end
33
-
28
+
34
29
  it "writes integer using alternate" do
35
- @data.v = 1
36
- @data.v.should == 1
37
- @data.value.should == 1
30
+ data.v = 1
31
+ data.v.should == 1
32
+ data.value.should == 1
38
33
  end
39
34
  end
40
-
41
35
  end
42
-
36
+
43
37
  describe "validation" do
44
-
45
38
  it "stubs valid? with true" do
46
39
  data = Rats::Data.new
47
40
  data.valid?.should be_true
48
41
  end
49
-
42
+
50
43
  it "responds to error" do
51
44
  data = Rats::Data.new
52
45
  data.respond_to?('error').should be_true
53
46
  end
54
-
55
47
  end
56
-
48
+
57
49
  describe "methods" do
58
-
59
50
  it "pads the value" do
60
51
  data = Rats::Data.new(1)
61
52
  data.to_p.should == "1"
62
-
63
- #Rats::Data.should_receive(:padding_width).twice.and_return(3)
53
+
64
54
  Rats::Data.expects(:padding_width).twice.returns(3)
65
55
  data.to_p.should == " 1"
66
-
67
- #Rats::Data.should_receive(:padding_value).and_return("0")
56
+
68
57
  Rats::Data.expects(:padding_value).returns("0")
69
58
  data.to_p.should == "001"
70
59
  end
71
-
60
+
72
61
  it "converts to string" do
73
62
  data = Rats::Data.new(1)
74
63
  data.to_s.should == "1"
75
64
  end
76
-
65
+
77
66
  it "resets a value" do
78
67
  data = Rats::Data.new(1)
79
68
  data.v.should == 1
80
69
  data.nil!
81
70
  data.v.should be_nil
82
71
  end
83
-
84
72
  end
85
-
73
+
86
74
  describe "errors" do
87
-
88
75
  it "responds to raise_errors!" do
89
76
  data = Rats::Data.new
90
77
  data.respond_to?('raise_errors!').should be_true
91
78
  end
92
-
79
+
93
80
  it "responds to raise_errors?" do
94
81
  data = Rats::Data.new
95
82
  data.respond_to?('raise_errors?').should be_true
96
83
  end
97
-
84
+
98
85
  it "doesn't initially raise errors" do
99
86
  data = Rats::Data.new
100
87
  data.raise_errors?.should be_false
101
88
  end
102
-
89
+
103
90
  it "will raise errors if set" do
104
91
  data = Rats::Data.new(nil, true)
105
92
  data.raise_errors?.should be_true
106
93
  end
107
-
108
94
  end
109
-
110
- end
95
+ end