thirst 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p194"
8
+
9
+ #
10
+ # First we attempt to load the desired environment directly from the environment
11
+ # file. This is very fast and efficicent compared to running through the entire
12
+ # CLI and selector. If you want feedback on which environment was used then
13
+ # insert the word 'use' after --create as this triggers verbose mode.
14
+ #
15
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
16
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
17
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
18
+ else
19
+ # If the environment file has not yet been created, use the RVM CLI to select.
20
+ rvm --create use "$environment_id"
21
+ fi
22
+
23
+ #
24
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
25
+ # it be automatically loaded. Uncomment the following and adjust the filename if
26
+ # necessary.
27
+ #
28
+ # filename=".gems"
29
+ # if [[ -s "$filename" ]] ; then
30
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
31
+ # fi
32
+
33
+ #
34
+ # If you use bundler and would like to run bundle each time you enter the
35
+ # directory, you can uncomment the following code.
36
+ #
37
+ # # Ensure that Bundler is installed. Install it if it is not.
38
+ # if ! command -v bundle >/dev/null; then
39
+ # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
40
+ # gem install bundler
41
+ # fi
42
+ #
43
+ # # Bundle while reducing excess noise.
44
+ # printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
45
+ # bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
46
+ #
47
+
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'mechanize'
7
+ gem 'geocoder'
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem 'rspec'
13
+ gem 'bundler'
14
+ gem 'jeweler'
15
+ gem 'guard-rspec'
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ domain_name (0.5.3)
6
+ unf (~> 0.0.3)
7
+ ffi (1.1.5)
8
+ geocoder (1.1.2)
9
+ git (1.2.5)
10
+ guard (1.3.2)
11
+ listen (>= 0.4.2)
12
+ thor (>= 0.14.6)
13
+ guard-rspec (1.2.1)
14
+ guard (>= 1.1)
15
+ jeweler (1.8.4)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ rdoc
20
+ json (1.7.5)
21
+ listen (0.4.7)
22
+ rb-fchange (~> 0.0.5)
23
+ rb-fsevent (~> 0.9.1)
24
+ rb-inotify (~> 0.8.8)
25
+ mechanize (2.5.1)
26
+ domain_name (~> 0.5, >= 0.5.1)
27
+ mime-types (~> 1.17, >= 1.17.2)
28
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
29
+ net-http-persistent (~> 2.5, >= 2.5.2)
30
+ nokogiri (~> 1.4)
31
+ ntlm-http (~> 0.1, >= 0.1.1)
32
+ webrobots (~> 0.0, >= 0.0.9)
33
+ mime-types (1.19)
34
+ net-http-digest_auth (1.2.1)
35
+ net-http-persistent (2.7)
36
+ nokogiri (1.5.5)
37
+ ntlm-http (0.1.1)
38
+ rake (0.9.2.2)
39
+ rb-fchange (0.0.5)
40
+ ffi
41
+ rb-fsevent (0.9.1)
42
+ rb-inotify (0.8.8)
43
+ ffi (>= 0.5.0)
44
+ rdoc (3.12)
45
+ json (~> 1.4)
46
+ rspec (2.11.0)
47
+ rspec-core (~> 2.11.0)
48
+ rspec-expectations (~> 2.11.0)
49
+ rspec-mocks (~> 2.11.0)
50
+ rspec-core (2.11.1)
51
+ rspec-expectations (2.11.2)
52
+ diff-lcs (~> 1.1.3)
53
+ rspec-mocks (2.11.2)
54
+ thor (0.16.0)
55
+ unf (0.0.5)
56
+ unf_ext
57
+ unf_ext (0.0.5)
58
+ webrobots (0.0.13)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ bundler
65
+ geocoder
66
+ guard-rspec
67
+ jeweler
68
+ mechanize
69
+ rspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch('lib/thirst.rb') { "spec" }
7
+ watch(%r{^lib/thirst/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
10
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Fredrik Rubensson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ thirst
2
+ ======
3
+
4
+ If you ever wanted to:
5
+
6
+ Pub.find
7
+
8
+ to get the nearest decent pub - then this gem is for you. Just:
9
+
10
+ gem install thirst
11
+
12
+ and integrate it in whatever application you need it in. Currently you can get all pubs with:
13
+
14
+ require 'thirst'
15
+ Pub.all
16
+
17
+ and if you want the pub closest to where your IP is thought to be you can
18
+
19
+ Pub.find
20
+
21
+ Each pub has a name, a latitude and a longitude. More will come later.
22
+
23
+
24
+ limitations
25
+ ===========
26
+
27
+ The gem is backed up with pubs in Sweden from the list maintained by Svenska Ölfrämjandet. If you feel you need this for your own country go ahead and contribute.
28
+
29
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "thirst"
18
+ gem.homepage = "http://github.com/froderik/thirst"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Pub.find if user.in_sweden?}
21
+ gem.description = %Q{Pub.find if user.in_sweden?}
22
+ gem.email = "fredrik@eldfluga.se"
23
+ gem.authors = ["Fredrik Rubensson"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+
36
+ task :default => :test
37
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,61 @@
1
+ require 'mechanize'
2
+ require 'nokogiri'
3
+ require 'json'
4
+ require 'geocoder'
5
+
6
+ include Geocoder::Calculations
7
+
8
+ class Pub
9
+ attr_accessor :name, :latitude, :longitude
10
+
11
+ def location
12
+ [latitude, longitude]
13
+ end
14
+
15
+ def Pub::find
16
+ agent = Mechanize.new
17
+ page = agent.get 'http://freegeoip.net/json/'
18
+ my_location = JSON.parse page.body
19
+ my_latitude = my_location['latitude']
20
+ my_longitude = my_location['longitude']
21
+ my_location = [my_latitude,my_longitude]
22
+ sorted_pubs = Pub::all.sort do |one, other|
23
+ distance_to_one = distance_between my_location, one.location
24
+ distance_to_other = distance_between my_location, other.location
25
+ distance_to_one <=> distance_to_other
26
+ end
27
+ sorted_pubs.first
28
+ end
29
+
30
+ def Pub::all
31
+ Pub::get_me_them_pubs
32
+ end
33
+
34
+ def Pub::get_me_them_pubs
35
+ unless defined? @@pubs
36
+ @@pubs = load_pub_list
37
+ end
38
+ @@pubs
39
+ end
40
+
41
+ def Pub::load_pub_list
42
+ parsed_xml = Nokogiri.parse get_xml_from_olframjandet
43
+ landmark_nodes = parsed_xml.search './/lm:landmark'
44
+ landmark_nodes.map { |landmark| Pub::one_node_to_pub( landmark ) }
45
+ end
46
+
47
+ def Pub::get_xml_from_olframjandet
48
+ agent = Mechanize.new
49
+ agent.get 'http://www.svenskaolframjandet.se' # seems like you need to get a session to get the file
50
+ xml_page = agent.get 'http://www.svenskaolframjandet.se/system/files/Pubs.lmx'
51
+ xml_page.body
52
+ end
53
+
54
+ def Pub::one_node_to_pub landmark
55
+ pub = Pub.new
56
+ pub.name = landmark.search( './/lm:name' ) .inner_text
57
+ pub.latitude = landmark.search( './/lm:latitude' ) .inner_text.to_f
58
+ pub.longitude = landmark.search( './/lm:longitude' ).inner_text.to_f
59
+ pub
60
+ end
61
+ end
data/lib/thirst.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ require 'thirst/thirst_quencher'
3
+
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
18
+
19
+ require 'thirst'
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pub do
4
+ it "should find all pubs" do
5
+ list_of_pubs = Pub.all
6
+ list_of_pubs.size.should > 150
7
+ end
8
+
9
+ it "should find at least one Bishops" do
10
+ Pub.all.detect {|pub| pub.name =~ /Bishops/ } .should_not be_nil
11
+ end
12
+
13
+ it "should find names on em all" do
14
+ Pub.all.each { |pub| pub.name.should_not be_nil }
15
+ end
16
+
17
+ it "should find latitude on em all" do
18
+ Pub.all.each { |pub| pub.latitude.should_not be_nil }
19
+ end
20
+
21
+ it "should find longitude on em all" do
22
+ Pub.all.each { |pub| pub.longitude.should_not be_nil }
23
+ end
24
+
25
+ it "should find one pub near me" do
26
+ nearest_pub = Pub.find
27
+ nearest_pub.name .should_not be_nil
28
+ nearest_pub.latitude .should_not be_nil
29
+ nearest_pub.longitude.should_not be_nil
30
+ end
31
+ end
data/thirst.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "thirst"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Fredrik Rubensson"]
12
+ s.date = "2012-08-19"
13
+ s.description = "Pub.find if user.in_sweden?"
14
+ s.email = "fredrik@eldfluga.se"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "Guardfile",
26
+ "LICENSE.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "lib/thirst.rb",
31
+ "lib/thirst/thirst_quencher.rb",
32
+ "spec/spec_helper.rb",
33
+ "spec/thirst_quencher_spec.rb",
34
+ "thirst.gemspec"
35
+ ]
36
+ s.homepage = "http://github.com/froderik/thirst"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.15"
40
+ s.summary = "Pub.find if user.in_sweden?"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<mechanize>, [">= 0"])
47
+ s.add_runtime_dependency(%q<geocoder>, [">= 0"])
48
+ s.add_development_dependency(%q<rspec>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
51
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<mechanize>, [">= 0"])
54
+ s.add_dependency(%q<geocoder>, [">= 0"])
55
+ s.add_dependency(%q<rspec>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, [">= 0"])
57
+ s.add_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<mechanize>, [">= 0"])
62
+ s.add_dependency(%q<geocoder>, [">= 0"])
63
+ s.add_dependency(%q<rspec>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, [">= 0"])
65
+ s.add_dependency(%q<jeweler>, [">= 0"])
66
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
67
+ end
68
+ end
69
+
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thirst
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fredrik Rubensson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &2157550900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157550900
25
+ - !ruby/object:Gem::Dependency
26
+ name: geocoder
27
+ requirement: &2157550420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2157550420
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2157549920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2157549920
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &2157549400 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2157549400
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &2157548880 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2157548880
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: &2157548360 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2157548360
80
+ description: Pub.find if user.in_sweden?
81
+ email: fredrik@eldfluga.se
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.md
87
+ files:
88
+ - .document
89
+ - .rspec
90
+ - .rvmrc
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - Guardfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - VERSION
98
+ - lib/thirst.rb
99
+ - lib/thirst/thirst_quencher.rb
100
+ - spec/spec_helper.rb
101
+ - spec/thirst_quencher_spec.rb
102
+ - thirst.gemspec
103
+ homepage: http://github.com/froderik/thirst
104
+ licenses:
105
+ - MIT
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ segments:
117
+ - 0
118
+ hash: -1786957553276533335
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.15
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Pub.find if user.in_sweden?
131
+ test_files: []