border_patrol 0.1.0 → 0.1.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/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +1 -9
- data/LICENSE.txt +19 -0
- data/README.markdown +1 -1
- data/Rakefile +2 -8
- data/border_patrol.gemspec +6 -13
- data/lib/VERSION +1 -1
- data/lib/border_patrol/polygon.rb +9 -5
- data/script/ci +10 -0
- data/spec/lib/border_patrol/polygon_spec.rb +4 -4
- data/spec/spec_helper.rb +2 -15
- metadata +41 -59
- data/Gemfile.lock +0 -31
- data/spec/spec.opts +0 -4
- data/spec/support/formatters/compact_progress_bar_formatter.rb +0 -133
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright © 2009 Square, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the “Software”), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# BorderPatrol
|
2
2
|
|
3
|
-
BorderPatrol
|
3
|
+
BorderPatrol allows you import a KML file and then check if points are inside or outside the polygons the file defines.
|
4
4
|
|
5
5
|
The KML file may have multiple polygons defined, google maps is a good source.
|
6
6
|
|
data/Rakefile
CHANGED
@@ -3,13 +3,7 @@ require 'bundler'
|
|
3
3
|
Bundler.setup
|
4
4
|
|
5
5
|
require 'rake'
|
6
|
-
require 'spec/rake/spectask'
|
7
|
-
|
8
|
-
|
9
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
10
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
11
|
-
spec.libs << 'spec'
|
12
|
-
spec.spec_opts = ["--options", "spec/spec.opts"]
|
13
|
-
end
|
14
6
|
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
9
|
task :default => :spec
|
data/border_patrol.gemspec
CHANGED
@@ -1,28 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'bundler'
|
4
|
-
|
5
3
|
Gem::Specification.new do |s|
|
6
4
|
s.name = "border_patrol"
|
7
5
|
s.version = File.read("lib/VERSION").strip
|
8
|
-
|
9
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
-
s.rubygems_version = "1.3.7"
|
11
|
-
|
12
6
|
s.authors = ["Zach Brock", "Matt Wilson"]
|
13
7
|
s.email = "eng@squareup.com"
|
14
|
-
|
15
8
|
s.date = "2010-10-20"
|
16
9
|
s.description = "Lets you import a KML file and then check if points are inside or outside the polygons the file defines."
|
17
10
|
s.summary = "Import and query KML regions"
|
18
11
|
s.homepage = "http://github.com/square/border_patrol"
|
19
12
|
|
20
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
21
|
-
|
22
13
|
s.require_paths = ["lib"]
|
23
|
-
|
24
|
-
s.
|
25
|
-
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
16
|
+
|
17
|
+
s.add_dependency("nokogiri", ">= 1.4.3.1")
|
26
18
|
|
27
|
-
s.
|
19
|
+
s.add_development_dependency("rake")
|
20
|
+
s.add_development_dependency("rspec", "~> 2.6.0")
|
28
21
|
end
|
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -1,18 +1,22 @@
|
|
1
|
+
require 'forwardable'
|
1
2
|
module BorderPatrol
|
2
|
-
class Polygon
|
3
|
-
|
3
|
+
class Polygon
|
4
|
+
extend Forwardable
|
5
|
+
def initialize(*args)
|
4
6
|
args.flatten!
|
5
7
|
args.uniq!
|
6
8
|
raise InsufficientPointsToActuallyFormAPolygonError unless args.size > 2
|
7
|
-
|
9
|
+
@points = Array.new(args)
|
8
10
|
end
|
9
11
|
|
12
|
+
def_delegators :@points, :size, :each, :first, :include?, :[], :index
|
13
|
+
|
10
14
|
def ==(other)
|
11
15
|
# Do we have the right number of points?
|
12
16
|
return false unless other.size == size
|
13
17
|
|
14
18
|
# Are the points in the right order?
|
15
|
-
first, second =
|
19
|
+
first, second = first(2)
|
16
20
|
index = other.index(first)
|
17
21
|
return false unless index
|
18
22
|
direction = (other[index-1] == second) ? -1 : 1
|
@@ -28,7 +32,7 @@ module BorderPatrol
|
|
28
32
|
|
29
33
|
# Quick and dirty hash function
|
30
34
|
def hash
|
31
|
-
inject(0) { |sum, point| sum += point.x + point.y }
|
35
|
+
@points.inject(0) { |sum, point| sum += point.x + point.y }
|
32
36
|
end
|
33
37
|
|
34
38
|
def contains_point?(point)
|
data/script/ci
ADDED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe BorderPatrol::Polygon do
|
4
4
|
describe "==" do
|
5
5
|
it "is true if polygons are congruent" do
|
6
6
|
points = [BorderPatrol::Point.new(1, 2), BorderPatrol::Point.new(3, 4), BorderPatrol::Point.new(0, 0)]
|
@@ -16,9 +16,9 @@ require 'spec_helper'
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "cares about order of points" do
|
19
|
-
points = [BorderPatrol::Point.new(1, 2), BorderPatrol::Point.new(3, 4), BorderPatrol::Point.new(5,5), BorderPatrol::Point.new(0, 0)]
|
19
|
+
points = [BorderPatrol::Point.new(1, 2), BorderPatrol::Point.new(3, 4), BorderPatrol::Point.new(5, 5), BorderPatrol::Point.new(0, 0)]
|
20
20
|
poly1 = BorderPatrol::Polygon.new(points)
|
21
|
-
points = [BorderPatrol::Point.new(5,5), BorderPatrol::Point.new(1, 2), BorderPatrol::Point.new(0, 0), BorderPatrol::Point.new(3, 4)]
|
21
|
+
points = [BorderPatrol::Point.new(5, 5), BorderPatrol::Point.new(1, 2), BorderPatrol::Point.new(0, 0), BorderPatrol::Point.new(3, 4)]
|
22
22
|
poly2 = BorderPatrol::Polygon.new(points)
|
23
23
|
|
24
24
|
poly1.should_not == poly2
|
@@ -52,7 +52,7 @@ require 'spec_helper'
|
|
52
52
|
|
53
53
|
it "can be instantiated with a arbitrary argument list" do
|
54
54
|
points = [BorderPatrol::Point.new(1, 2), BorderPatrol::Point.new(3, 4), BorderPatrol::Point.new(0, 0)]
|
55
|
-
poly1 = BorderPatrol::Polygon.new(*points)
|
55
|
+
poly1 = BorderPatrol::Polygon.new(* points)
|
56
56
|
poly2 = BorderPatrol::Polygon.new(points)
|
57
57
|
poly1.should == poly2
|
58
58
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,20 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'bundler'
|
3
3
|
Bundler.setup
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'border_patrol'
|
6
6
|
|
7
|
-
|
8
|
-
app_dirs = ['lib', 'lib/kaml_pen']
|
9
|
-
|
10
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
11
|
-
|
12
|
-
app_dirs.each do |app_dir|
|
13
|
-
Dir["#{base_dir}/spec/#{app_dir}/*.rb"].each do |f|
|
14
|
-
f.sub!('/spec','')
|
15
|
-
f.sub!('_spec','')
|
16
|
-
require f
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
Spec::Runner.configure do |config|
|
7
|
+
RSpec.configure do |config|
|
21
8
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: border_patrol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zach Brock
|
@@ -20,39 +20,26 @@ date: 2010-10-20 00:00:00 -07:00
|
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - "="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 49
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 8
|
32
|
-
- 7
|
33
|
-
version: 0.8.7
|
34
|
-
name: rake
|
23
|
+
name: nokogiri
|
35
24
|
prerelease: false
|
36
|
-
requirement:
|
37
|
-
type: :development
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
40
26
|
none: false
|
41
27
|
requirements:
|
42
|
-
- - "
|
28
|
+
- - ">="
|
43
29
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
30
|
+
hash: 113
|
45
31
|
segments:
|
46
32
|
- 1
|
33
|
+
- 4
|
47
34
|
- 3
|
48
|
-
-
|
49
|
-
version: 1.3.
|
50
|
-
|
51
|
-
|
52
|
-
requirement: *id002
|
53
|
-
type: :development
|
35
|
+
- 1
|
36
|
+
version: 1.4.3.1
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
54
39
|
- !ruby/object:Gem::Dependency
|
55
|
-
|
40
|
+
name: rake
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
56
43
|
none: false
|
57
44
|
requirements:
|
58
45
|
- - ">="
|
@@ -61,27 +48,24 @@ dependencies:
|
|
61
48
|
segments:
|
62
49
|
- 0
|
63
50
|
version: "0"
|
64
|
-
name: progressbar
|
65
|
-
prerelease: false
|
66
|
-
requirement: *id003
|
67
51
|
type: :development
|
52
|
+
version_requirements: *id002
|
68
53
|
- !ruby/object:Gem::Dependency
|
69
|
-
|
54
|
+
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
70
57
|
none: false
|
71
58
|
requirements:
|
72
|
-
- -
|
59
|
+
- - ~>
|
73
60
|
- !ruby/object:Gem::Version
|
74
|
-
hash:
|
61
|
+
hash: 23
|
75
62
|
segments:
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
prerelease: false
|
83
|
-
requirement: *id004
|
84
|
-
type: :runtime
|
63
|
+
- 2
|
64
|
+
- 6
|
65
|
+
- 0
|
66
|
+
version: 2.6.0
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
85
69
|
description: Lets you import a KML file and then check if points are inside or outside the polygons the file defines.
|
86
70
|
email: eng@squareup.com
|
87
71
|
executables: []
|
@@ -91,31 +75,31 @@ extensions: []
|
|
91
75
|
extra_rdoc_files: []
|
92
76
|
|
93
77
|
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.markdown
|
83
|
+
- Rakefile
|
84
|
+
- border_patrol.gemspec
|
85
|
+
- lib/VERSION
|
86
|
+
- lib/border_patrol.rb
|
94
87
|
- lib/border_patrol/polygon.rb
|
95
88
|
- lib/border_patrol/region.rb
|
96
|
-
-
|
97
|
-
- lib/VERSION
|
89
|
+
- script/ci
|
98
90
|
- spec/lib/border_patrol/polygon_spec.rb
|
99
91
|
- spec/lib/border_patrol/region_spec.rb
|
100
92
|
- spec/lib/border_patrol_spec.rb
|
101
|
-
- spec/spec.opts
|
102
93
|
- spec/spec_helper.rb
|
103
94
|
- spec/support/colorado-test.kml
|
104
|
-
- spec/support/formatters/compact_progress_bar_formatter.rb
|
105
95
|
- spec/support/multi-polygon-test.kml
|
106
|
-
- border_patrol.gemspec
|
107
|
-
- Rakefile
|
108
|
-
- README.markdown
|
109
|
-
- .gitignore
|
110
|
-
- Gemfile
|
111
|
-
- Gemfile.lock
|
112
96
|
has_rdoc: true
|
113
97
|
homepage: http://github.com/square/border_patrol
|
114
98
|
licenses: []
|
115
99
|
|
116
100
|
post_install_message:
|
117
|
-
rdoc_options:
|
118
|
-
|
101
|
+
rdoc_options: []
|
102
|
+
|
119
103
|
require_paths:
|
120
104
|
- lib
|
121
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -139,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
123
|
requirements: []
|
140
124
|
|
141
125
|
rubyforge_project:
|
142
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.6.2
|
143
127
|
signing_key:
|
144
128
|
specification_version: 3
|
145
129
|
summary: Import and query KML regions
|
@@ -147,8 +131,6 @@ test_files:
|
|
147
131
|
- spec/lib/border_patrol/polygon_spec.rb
|
148
132
|
- spec/lib/border_patrol/region_spec.rb
|
149
133
|
- spec/lib/border_patrol_spec.rb
|
150
|
-
- spec/spec.opts
|
151
134
|
- spec/spec_helper.rb
|
152
135
|
- spec/support/colorado-test.kml
|
153
|
-
- spec/support/formatters/compact_progress_bar_formatter.rb
|
154
136
|
- spec/support/multi-polygon-test.kml
|
data/Gemfile.lock
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
---
|
2
|
-
dependencies:
|
3
|
-
rake:
|
4
|
-
group:
|
5
|
-
- :development
|
6
|
-
version: = 0.8.7
|
7
|
-
rspec:
|
8
|
-
group:
|
9
|
-
- :development
|
10
|
-
version: = 1.3.0
|
11
|
-
progressbar:
|
12
|
-
group:
|
13
|
-
- :development
|
14
|
-
version: ">= 0"
|
15
|
-
nokogiri:
|
16
|
-
group:
|
17
|
-
- :default
|
18
|
-
version: = 1.4.3.1
|
19
|
-
specs:
|
20
|
-
- rake:
|
21
|
-
version: 0.8.7
|
22
|
-
- nokogiri:
|
23
|
-
version: 1.4.3.1
|
24
|
-
- progressbar:
|
25
|
-
version: 0.9.0
|
26
|
-
- rspec:
|
27
|
-
version: 1.3.0
|
28
|
-
hash: cbbadd85a1348941a32f127e7ae81222e0cfb8bc
|
29
|
-
sources:
|
30
|
-
- Rubygems:
|
31
|
-
uri: http://gemcutter.org
|
data/spec/spec.opts
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
# Originally by Nicholas A. Evans. See LICENSE.txt at
|
2
|
-
# http://gist.github.com/275257
|
3
|
-
#
|
4
|
-
# Note: includes modifications from the original to use '=' for the progress
|
5
|
-
# bar mark and keep the cursor from hopping all around during the animation.
|
6
|
-
#
|
7
|
-
# This version is compatible with RSpec 1.2.9 and ProgressBar 0.9.0.
|
8
|
-
|
9
|
-
require 'spec/runner/formatter/base_text_formatter'
|
10
|
-
require 'progressbar'
|
11
|
-
|
12
|
-
module Spec
|
13
|
-
module Runner
|
14
|
-
module Formatter
|
15
|
-
class CompactProgressBarFormatter < BaseTextFormatter
|
16
|
-
# Threshold for slow specs, in seconds.
|
17
|
-
# Anything that takes longer than this will be printed out
|
18
|
-
THRESHOLD = 1.0 unless defined?(THRESHOLD)
|
19
|
-
|
20
|
-
attr_reader :total, :current
|
21
|
-
|
22
|
-
def start(example_count)
|
23
|
-
@current = 0
|
24
|
-
@total = example_count
|
25
|
-
@error_state = :all_passing
|
26
|
-
@pbar = ProgressBar.new("#{example_count} examples", example_count, output)
|
27
|
-
@pbar.instance_variable_set("@bar_mark", "=")
|
28
|
-
end
|
29
|
-
|
30
|
-
def example_started(example)
|
31
|
-
super
|
32
|
-
@start_time = Time.now
|
33
|
-
end
|
34
|
-
|
35
|
-
def example_passed(example)
|
36
|
-
print_warning_if_slow(example_group.description,
|
37
|
-
example.description,
|
38
|
-
Time.now - @start_time)
|
39
|
-
increment
|
40
|
-
end
|
41
|
-
|
42
|
-
def example_pending(example, message, deprecated_pending_location=nil)
|
43
|
-
immediately_dump_pending(example.description, message, pending_caller)
|
44
|
-
mark_error_state_pending
|
45
|
-
increment
|
46
|
-
end
|
47
|
-
|
48
|
-
def example_failed(example, counter, failure)
|
49
|
-
immediately_dump_failure(counter, failure)
|
50
|
-
mark_error_state_failed
|
51
|
-
increment
|
52
|
-
end
|
53
|
-
|
54
|
-
def start_dump
|
55
|
-
with_color do
|
56
|
-
@pbar.finish
|
57
|
-
end
|
58
|
-
output.flush
|
59
|
-
end
|
60
|
-
|
61
|
-
def dump_failure(*args)
|
62
|
-
# no-op; we summarized failures as we were running
|
63
|
-
end
|
64
|
-
|
65
|
-
def method_missing(sym, *args)
|
66
|
-
# ignore
|
67
|
-
end
|
68
|
-
|
69
|
-
# Adapted from BaseTextFormatter#dump_failure
|
70
|
-
def immediately_dump_failure(counter, failure)
|
71
|
-
erase_current_line
|
72
|
-
output.print "#{counter.to_s}) "
|
73
|
-
output.puts colorize_failure("#{failure.header}\n#{failure.exception.message}", failure)
|
74
|
-
output.puts format_backtrace(failure.exception.backtrace)
|
75
|
-
output.puts
|
76
|
-
end
|
77
|
-
|
78
|
-
# Adapted from BaseTextFormatter#dump_pending
|
79
|
-
def immediately_dump_pending(desc, msg, called_from)
|
80
|
-
erase_current_line
|
81
|
-
output.puts yellow("PENDING SPEC:") + " #{desc} (#{msg})"
|
82
|
-
output.puts " Called from #{called_from}" if called_from
|
83
|
-
end
|
84
|
-
|
85
|
-
def increment
|
86
|
-
with_color do
|
87
|
-
@current += 1
|
88
|
-
# Since we're constantly erasing the line, make sure the progress is
|
89
|
-
# printed even when the bar hasn't changed
|
90
|
-
@pbar.instance_variable_set("@previous", 0)
|
91
|
-
@pbar.instance_variable_set("@title", " #{current}/#{total}")
|
92
|
-
@pbar.inc
|
93
|
-
end
|
94
|
-
output.flush
|
95
|
-
end
|
96
|
-
|
97
|
-
ERROR_STATE_COLORS = {
|
98
|
-
:all_passing => "\e[32m", # green
|
99
|
-
:some_pending => "\e[33m", # yellow
|
100
|
-
:some_failed => "\e[31m", # red
|
101
|
-
} unless defined?(ERROR_STATE_COLORS)
|
102
|
-
|
103
|
-
def with_color
|
104
|
-
output.print "\e[?25l" + ERROR_STATE_COLORS[@error_state] if colour?
|
105
|
-
yield
|
106
|
-
output.print "\e[0m\e[?25h" if colour?
|
107
|
-
end
|
108
|
-
|
109
|
-
def mark_error_state_failed
|
110
|
-
@error_state = :some_failed
|
111
|
-
end
|
112
|
-
|
113
|
-
def mark_error_state_pending
|
114
|
-
@error_state = :some_pending unless @error_state == :some_failed
|
115
|
-
end
|
116
|
-
|
117
|
-
def erase_current_line
|
118
|
-
output.print "\e[K"
|
119
|
-
end
|
120
|
-
|
121
|
-
def print_warning_if_slow(group, example, elapsed)
|
122
|
-
if elapsed > THRESHOLD
|
123
|
-
erase_current_line
|
124
|
-
output.print yellow("SLOW SPEC: #{sprintf("%.4f", elapsed)} ")
|
125
|
-
output.print " #{group} #{example}"
|
126
|
-
output.puts
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|