kamel 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.textile +4 -8
- data/Rakefile +3 -24
- data/kamel.gemspec +32 -0
- data/lib/kamel/overlay.rb +5 -11
- data/lib/kamel/version.rb +3 -0
- data/spec/kamel/overlay_spec.rb +3 -10
- data/spec/spec_helper.rb +8 -0
- data/spec/xpath_matchers.rb +75 -79
- metadata +93 -77
- data/HISTORY +0 -2
- data/VERSION +0 -1
data/Gemfile
ADDED
data/README.textile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
h1. Kamel
|
2
2
|
|
3
|
-
<pre><code>gem install
|
4
|
-
gem install kamel --source http://gemcutter.org/</code></pre>
|
3
|
+
<pre><code>gem install kamel</code></pre>
|
5
4
|
|
6
|
-
Create KML files for tasty overlays on google earth and google maps. Provides a
|
5
|
+
Create KML files for tasty overlays on google earth and google maps. Provides a
|
6
|
+
cleaner interface than ruby_kml (which it uses internally).
|
7
7
|
|
8
|
-
Tested on ruby 1.8.
|
8
|
+
Tested on ruby 1.8.7 and 1.9.3.
|
9
9
|
|
10
10
|
h2. Usage
|
11
11
|
|
@@ -26,7 +26,3 @@ overlay.name = 'Melbourne Train Stations'
|
|
26
26
|
)
|
27
27
|
end
|
28
28
|
puts overlay.to_kml</code></pre>
|
29
|
-
|
30
|
-
h2. Maturity
|
31
|
-
|
32
|
-
As far as I know this code is not being used in production, certainly not by me. It depends on a fork of kmlr which is no longer maintained and is not even published to rubygems. So, use at your own risk.
|
data/Rakefile
CHANGED
@@ -1,27 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Jeweler::Tasks.new do |gemspec|
|
4
|
-
gemspec.name = "kamel"
|
5
|
-
gemspec.summary = "Create KML files for tasty overlays on google earth and google maps"
|
6
|
-
gemspec.description = "Create KML files for tasty overlays on google earth and google maps"
|
7
|
-
gemspec.email = "contact@rhnh.net"
|
8
|
-
gemspec.homepage = "http://github.com/xaviershay/kamel"
|
9
|
-
gemspec.authors = ["Xavier Shay"]
|
10
|
-
gemspec.test_files = Dir["spec/**/*_spec.rb"]
|
11
|
-
gemspec.add_dependency("schleyfox-ruby_kml", [">= 0.1.4"])
|
12
|
-
gemspec.add_development_dependency("rspec", ["~> 1.3.0"])
|
13
|
-
end
|
14
|
-
rescue LoadError
|
15
|
-
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
16
|
-
end
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rspec/core/rake_task'
|
17
3
|
|
18
|
-
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
19
5
|
|
20
|
-
Spec::Rake::SpecTask.new do |t|
|
21
|
-
t.warning = false
|
22
|
-
t.rcov = false
|
23
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
-
end
|
25
|
-
|
26
|
-
task :test => :spec
|
27
6
|
task :default => :spec
|
data/kamel.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/kamel/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Xavier Shay"]
|
6
|
+
gem.email = ["contact@rhnh.net"]
|
7
|
+
gem.description = %q{Create KML files for tasty overlays on google earth and google maps}
|
8
|
+
gem.summary = %q{Create KML files for tasty overlays on google earth and google maps}
|
9
|
+
gem.homepage = "https://github.com/xaviershay/kamel"
|
10
|
+
|
11
|
+
gem.required_ruby_version = ">= 1.8.7"
|
12
|
+
gem.rubyforge_project = "kamel"
|
13
|
+
|
14
|
+
gem.add_development_dependency "rspec", "~> 2.9"
|
15
|
+
gem.add_development_dependency 'rake', '~> 0.9'
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'ruby_kml', '~> 0.1.4'
|
18
|
+
gem.add_runtime_dependency 'builder', '~> 3.0.0' #ruby_kml depends on builder but does not declare it's dependencies correctly
|
19
|
+
|
20
|
+
gem.files = Dir.glob("{spec,lib}/**/*.rb") + %w(
|
21
|
+
Gemfile
|
22
|
+
README.textile
|
23
|
+
LICENSE
|
24
|
+
Rakefile
|
25
|
+
kamel.gemspec
|
26
|
+
)
|
27
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
28
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
29
|
+
gem.name = "kamel"
|
30
|
+
gem.require_paths = ["lib"]
|
31
|
+
gem.version = Kamel::VERSION
|
32
|
+
end
|
data/lib/kamel/overlay.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'kml'
|
3
|
-
rescue LoadError
|
4
|
-
puts "You must have ruby_kml either installed to use Kamel - either as a gem or available in your path"
|
5
|
-
puts "gem install schleyfox-ruby_kml --source http://gems.github.com"
|
6
|
-
exit
|
7
|
-
end
|
1
|
+
require 'kml'
|
8
2
|
|
9
|
-
module Kamel
|
3
|
+
module Kamel
|
10
4
|
class Overlay
|
11
5
|
attr_accessor :prefix
|
12
6
|
attr_accessor :name
|
@@ -30,7 +24,7 @@ module Kamel
|
|
30
24
|
:icon_style => KML::IconStyle.new(
|
31
25
|
:icon => KML::Icon.new(:href => icon)
|
32
26
|
)
|
33
|
-
)
|
27
|
+
)
|
34
28
|
}
|
35
29
|
self.placemarks.each do |placemark|
|
36
30
|
attrs = {}
|
@@ -40,7 +34,7 @@ module Kamel
|
|
40
34
|
attrs[:style_url] = '#' + [prefix, 'style', self.icons.index(placemark[:icon])].join('-') unless placemark[:icon].nil?
|
41
35
|
doc.features << KML::Placemark.new(attrs)
|
42
36
|
end
|
43
|
-
|
37
|
+
|
44
38
|
kml = KMLFile.new
|
45
39
|
kml.objects << doc
|
46
40
|
kml.render
|
@@ -49,7 +43,7 @@ module Kamel
|
|
49
43
|
protected
|
50
44
|
|
51
45
|
def icons
|
52
|
-
self.placemarks.collect {|x| x[:icon]}.compact.uniq.sort
|
46
|
+
self.placemarks.collect {|x| x[:icon]}.compact.uniq.sort
|
53
47
|
end
|
54
48
|
end
|
55
49
|
end
|
data/spec/kamel/overlay_spec.rb
CHANGED
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
require 'spec'
|
4
|
-
require 'kamel'
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + '/../xpath_matchers')
|
6
|
-
|
7
|
-
|
8
|
-
require 'rexml/document'
|
9
|
-
require 'rexml/element'
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
10
3
|
|
11
4
|
describe Kamel::Overlay, '#to_kml' do
|
12
5
|
before(:each) do
|
@@ -30,7 +23,7 @@ describe Kamel::Overlay, '#to_kml' do
|
|
30
23
|
@doc.should match_xpath("/kml/Document/Placemark[2]/name", "placemark-2")
|
31
24
|
@doc.should match_xpath("/kml/Document/Placemark[3]/name", "placemark-3")
|
32
25
|
end
|
33
|
-
|
26
|
+
|
34
27
|
it 'records the description of each placemark if it is provided' do
|
35
28
|
#TODO Figure out how to check for CDATA
|
36
29
|
@doc.should have_xpath("/kml/Document/Placemark[1]/description")
|
data/spec/spec_helper.rb
ADDED
data/spec/xpath_matchers.rb
CHANGED
@@ -1,105 +1,101 @@
|
|
1
1
|
# http://blog.wolfman.com/articles/2008/01/02/xpath-matchers-for-rspec
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@xpath = xpath
|
10
|
-
end
|
11
|
-
|
12
|
-
def matches?(response)
|
13
|
-
@response = response
|
14
|
-
doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response)
|
15
|
-
match = REXML::XPath.match(doc, @xpath)
|
16
|
-
not match.empty?
|
17
|
-
end
|
3
|
+
module XpathMatchers
|
4
|
+
# check if the xpath exists one or more times
|
5
|
+
class HaveXpath
|
6
|
+
def initialize(xpath)
|
7
|
+
@xpath = xpath
|
8
|
+
end
|
18
9
|
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
def matches?(response)
|
11
|
+
@response = response
|
12
|
+
doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response)
|
13
|
+
match = REXML::XPath.match(doc, @xpath)
|
14
|
+
not match.empty?
|
15
|
+
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
def failure_message
|
18
|
+
"Did not find expected xpath #{@xpath}"
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
21
|
+
def negative_failure_message
|
22
|
+
"Did find unexpected xpath #{@xpath}"
|
30
23
|
end
|
31
24
|
|
32
|
-
def
|
33
|
-
|
25
|
+
def description
|
26
|
+
"match the xpath expression #{@xpath}"
|
34
27
|
end
|
28
|
+
end
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
class MatchXpath
|
40
|
-
def initialize(xpath, val)
|
41
|
-
@xpath = xpath
|
42
|
-
@val= val
|
43
|
-
end
|
30
|
+
def have_xpath(xpath)
|
31
|
+
HaveXpath.new(xpath)
|
32
|
+
end
|
44
33
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
when REXML::Element
|
54
|
-
e.text
|
55
|
-
else
|
56
|
-
e.to_s
|
57
|
-
end
|
58
|
-
return false unless @val == @actual_val
|
59
|
-
end
|
60
|
-
return ok
|
61
|
-
end
|
34
|
+
# check if the xpath has the specified value
|
35
|
+
# value is a string and there must be a single result to match its
|
36
|
+
# equality against
|
37
|
+
class MatchXpath
|
38
|
+
def initialize(xpath, val)
|
39
|
+
@xpath = xpath
|
40
|
+
@val= val
|
41
|
+
end
|
62
42
|
|
63
|
-
|
64
|
-
|
43
|
+
def matches?(response)
|
44
|
+
@response = response
|
45
|
+
doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response)
|
46
|
+
ok= true
|
47
|
+
REXML::XPath.each(doc, @xpath) do |e|
|
48
|
+
@actual_val= case e
|
49
|
+
when REXML::Attribute
|
50
|
+
e.to_s
|
51
|
+
when REXML::Element
|
52
|
+
e.text
|
53
|
+
else
|
54
|
+
e.to_s
|
55
|
+
end
|
56
|
+
return false unless @val == @actual_val
|
65
57
|
end
|
58
|
+
return ok
|
59
|
+
end
|
66
60
|
|
67
|
-
|
68
|
-
|
69
|
-
end
|
61
|
+
def failure_message
|
62
|
+
"The xpath #{@xpath} did not have the value '#{@val}'\nIt was '#{@actual_val}'"
|
70
63
|
end
|
71
64
|
|
72
|
-
def
|
73
|
-
|
65
|
+
def description
|
66
|
+
"match the xpath expression #{@xpath} with #{@val}"
|
74
67
|
end
|
68
|
+
end
|
75
69
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
@xpath= xpath
|
80
|
-
@num = num
|
81
|
-
end
|
70
|
+
def match_xpath(xpath, val)
|
71
|
+
MatchXpath.new(xpath, val)
|
72
|
+
end
|
82
73
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
74
|
+
# checks if the given xpath occurs num times
|
75
|
+
class HaveNodes #:nodoc:
|
76
|
+
def initialize(xpath, num)
|
77
|
+
@xpath= xpath
|
78
|
+
@num = num
|
79
|
+
end
|
90
80
|
|
91
|
-
|
92
|
-
|
93
|
-
|
81
|
+
def matches?(response)
|
82
|
+
@response = response
|
83
|
+
doc = response.is_a?(REXML::Document) ? response : REXML::Document.new(@response)
|
84
|
+
match = REXML::XPath.match(doc, @xpath)
|
85
|
+
@num_found= match.size
|
86
|
+
@num_found == @num
|
87
|
+
end
|
94
88
|
|
95
|
-
|
96
|
-
|
97
|
-
end
|
89
|
+
def failure_message
|
90
|
+
"Did not find expected number of nodes #{@num} in xpath #{@xpath}\nFound #{@num_found}"
|
98
91
|
end
|
99
92
|
|
100
|
-
def
|
101
|
-
|
93
|
+
def description
|
94
|
+
"match the number of nodes #{@num}"
|
102
95
|
end
|
96
|
+
end
|
103
97
|
|
98
|
+
def have_nodes(xpath, num)
|
99
|
+
HaveNodes.new(xpath, num)
|
104
100
|
end
|
105
101
|
end
|
metadata
CHANGED
@@ -1,107 +1,123 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: kamel
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 2
|
10
|
-
version: 0.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Xavier Shay
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
date: 2012-06-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.9'
|
22
|
+
type: :development
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.9'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.9'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.9'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby_kml
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
34
53
|
version: 0.1.4
|
35
54
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rspec
|
39
55
|
prerelease: false
|
40
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
57
|
none: false
|
42
|
-
requirements:
|
58
|
+
requirements:
|
43
59
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.4
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: builder
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
53
78
|
description: Create KML files for tasty overlays on google earth and google maps
|
54
|
-
email:
|
79
|
+
email:
|
80
|
+
- contact@rhnh.net
|
55
81
|
executables: []
|
56
|
-
|
57
82
|
extensions: []
|
58
|
-
|
59
|
-
|
60
|
-
-
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- spec/kamel/overlay_spec.rb
|
86
|
+
- spec/xpath_matchers.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- lib/kamel/version.rb
|
89
|
+
- lib/kamel/overlay.rb
|
90
|
+
- lib/kamel.rb
|
91
|
+
- Gemfile
|
61
92
|
- README.textile
|
62
|
-
files:
|
63
|
-
- HISTORY
|
64
93
|
- LICENSE
|
65
|
-
- README.textile
|
66
94
|
- Rakefile
|
67
|
-
-
|
68
|
-
|
69
|
-
- lib/kamel/overlay.rb
|
70
|
-
- spec/kamel/overlay_spec.rb
|
71
|
-
- spec/xpath_matchers.rb
|
72
|
-
has_rdoc: true
|
73
|
-
homepage: http://github.com/xaviershay/kamel
|
95
|
+
- kamel.gemspec
|
96
|
+
homepage: https://github.com/xaviershay/kamel
|
74
97
|
licenses: []
|
75
|
-
|
76
98
|
post_install_message:
|
77
99
|
rdoc_options: []
|
78
|
-
|
79
|
-
require_paths:
|
100
|
+
require_paths:
|
80
101
|
- lib
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
103
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
|
88
|
-
- 0
|
89
|
-
version: "0"
|
90
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 1.8.7
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
109
|
none: false
|
92
|
-
requirements:
|
93
|
-
- -
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
segments:
|
97
|
-
- 0
|
98
|
-
version: "0"
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
99
114
|
requirements: []
|
100
|
-
|
101
|
-
|
102
|
-
rubygems_version: 1.3.7
|
115
|
+
rubyforge_project: kamel
|
116
|
+
rubygems_version: 1.8.23
|
103
117
|
signing_key:
|
104
118
|
specification_version: 3
|
105
119
|
summary: Create KML files for tasty overlays on google earth and google maps
|
106
|
-
test_files:
|
120
|
+
test_files:
|
107
121
|
- spec/kamel/overlay_spec.rb
|
122
|
+
- spec/xpath_matchers.rb
|
123
|
+
- spec/spec_helper.rb
|
data/HISTORY
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.2
|