Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Cora::Location which handles reverse geolocation (for now)

  • Loading branch information...
commit fe95a81ac2bdb8905feade3adb75ff6009f1793e 1 parent 15d199d
@chendo authored
View
6 cora.gemspec
@@ -16,10 +16,12 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec"
s.add_development_dependency "guard-rspec"
s.add_development_dependency "rake"
-
+
+ s.add_runtime_dependency "geocoder"
+
s.files = `git ls-files 2> /dev/null`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/* 2> /dev/null`.split("\n")
s.executables = `git ls-files -- bin/* 2> /dev/null`.split("\n").map{ |f| File.basename(f) }
-
+
s.require_paths = ["lib"]
end
View
7 lib/cora.rb
@@ -1,8 +1,11 @@
require "cora/version"
require "cora/plugin"
+require "cora/location"
class Cora
+ attr_reader :location
+
def plugins
@plugins ||= []
end
@@ -49,6 +52,10 @@ def set_active_fiber(fiber)
@fiber = fiber
end
+ def set_location(latitude, longitude, extra = {})
+ @location = Location.new(latitude, longitude, extra)
+ end
+
def log(text)
$stderr.puts(text) if defined?(LOG)
end
View
34 lib/cora/location.rb
@@ -0,0 +1,34 @@
+require 'geocoder'
+
+class Cora::Location
+
+ extend Forwardable
+
+ def_delegators :result, :address, :city, :state, :state_code, :country, :country_code, :postal_code
+
+ attr_reader :latitude, :longitude, :extra
+
+ def initialize(latitude, longitude, extra = {})
+ @latitude = latitude
+ @longitude = longitude
+ @extra = extra
+ end
+
+ # Returns nil if geolocation failed, or an instance of Geocoder::Result::Google
+ # See: http://rubydoc.info/github/alexreisner/geocoder/master/Geocoder/Result/Google
+ def result
+ results.first
+ end
+
+ # Returns an array of objects of class Geocoder::Result::Google (probably)
+ def results
+ @results ||= perform_reverse_geocode
+ end
+
+ private
+
+ def perform_reverse_geocode
+ Geocoder.search([latitude, longitude].join(','))
+ end
+
+end
View
8 lib/cora/plugin.rb
@@ -5,6 +5,10 @@ class Cora::Plugin
CONFIRM_REGEX = /yes|yeah|yep|ok|confirm|affirmative|indeed|engage/i
DENY_REGEX = /no|nope|nah|cancel|negative/i
+ extend Forwardable
+
+ def_delegators :manager, :log, :location
+
attr_accessor :manager, :match_data
attr_reader :current_state
@@ -88,8 +92,4 @@ def set_state(state)
manager.set_priority_plugin(self)
end
- def log(*args)
- manager.log(*args)
- end
-
end
View
2  lib/cora/version.rb
@@ -1,3 +1,3 @@
class Cora
- VERSION = "0.0.3"
+ VERSION = "0.0.4"
end
Please sign in to comment.
Something went wrong with that request. Please try again.