weather_checker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/weather_checker.rb +61 -0
  2. metadata +142 -0
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'barometer'
3
+ require 'active_support'
4
+ require 'pry'
5
+
6
+ class WeatherChecker
7
+
8
+ class << self
9
+ attr_accessor :cache_time, :cache
10
+
11
+ WeatherChecker.cache_time = 10.minutes
12
+
13
+ WeatherChecker.cache = ActiveSupport::Cache::MemoryStore.new(:expires_in => WeatherChecker.cache_time)
14
+ end
15
+
16
+ attr_accessor :weather
17
+
18
+ def initialize weather_obj
19
+ @weather = weather_obj
20
+ end
21
+
22
+ def temperature_above? celsius_degrees
23
+ return celsius_degrees.to_i < weather.current.temperature.c
24
+ end
25
+
26
+ def rain_chance?
27
+ icons = weather.sources.map { |s|
28
+ class_name = "Barometer::WeatherService::#{s.to_s.gsub(/(^.|_.)/) { |x| x.gsub(/_/,'').upcase }}"
29
+ klass = class_name.split('::').inject(Kernel) { |scope, const_name| scope.const_get(const_name) }
30
+ klass._wet_icon_codes
31
+ }.flatten
32
+
33
+ return weather.current.wet? icons
34
+ end
35
+
36
+ def self.for_location(location)
37
+ barometer = WeatherChecker.get(location) || Barometer.new(location)
38
+ weather = barometer.measure
39
+ WeatherChecker.set(location, barometer)
40
+ WeatherChecker.new barometer.weather
41
+ end
42
+
43
+ private
44
+ def self.get(location)
45
+ WeatherChecker.cache.fetch(location)
46
+ end
47
+
48
+ def self.set(location, value)
49
+ WeatherChecker.cache.write(location, value)
50
+ end
51
+ end
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cristian Pereyra
9
+ - Damian Dome
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-04 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: barometer
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: active_support
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '2.6'
63
+ - !ruby/object:Gem::Dependency
64
+ name: mocha
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: fakeweb
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: pry
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A gem for checking and updating events based on weather conditions
112
+ email: criis.pereyra@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - lib/weather_checker.rb
118
+ homepage: http://rubygems.org/gems/weather_checker
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.24
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Check the weather conditions
142
+ test_files: []