pretty_weather 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +32 -0
- data/lib/pretty_weather/configuration.rb +14 -0
- data/lib/pretty_weather/engine.rb +7 -0
- data/lib/pretty_weather/pretty_weather_helper.rb +13 -0
- data/lib/pretty_weather/railtie.rb +11 -0
- data/lib/pretty_weather/version.rb +3 -0
- data/lib/pretty_weather/weather.rb +102 -0
- data/lib/pretty_weather.rb +5 -0
- data/lib/tasks/pretty_weather_tasks.rake +4 -0
- data/test/pretty_weather_test.rb +37 -0
- data/test/test_helper.rb +15 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a54343ab366b6f57c81262080c4cbf82f821fdde
|
4
|
+
data.tar.gz: e724868f95440475cf00528fe77059e2ce867706
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 673c51442b58c766da321701f1a1b52bf1661ee1dacc099373cd1717dcbb46eaeeeb8301441d59b9fea69048c581124600d0ef962c5b9d70ac4b56805e445017
|
7
|
+
data.tar.gz: 189943fa09b5aa614bc826139d1f3dc7b88f86d34aba62e79f988e57f3b743bd8167ec2ef5974c587144a944f8ca02aac5c227774526cb0055599883ced7009c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 YOURNAME
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'PrettyWeather'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module PrettyWeather
|
2
|
+
def weather_tag(city = Rails.application.config.pretty_weather.city_name, units = Rails.application.config.pretty_weather.units)
|
3
|
+
Weather.new(city, units).icon_tag
|
4
|
+
end
|
5
|
+
|
6
|
+
def weather_temp(city = Rails.application.config.pretty_weather.city_name, units = Rails.application.config.pretty_weather.units)
|
7
|
+
Weather.new(city, units).temp
|
8
|
+
end
|
9
|
+
|
10
|
+
def weather_condition(city = Rails.application.config.pretty_weather.city_name, units = Rails.application.config.pretty_weather.units)
|
11
|
+
Weather.new(city, units).weather
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Railtie < Rails::Railtie
|
2
|
+
initializer 'pretty_weather.initialize_pretty_weather_helper' do |app|
|
3
|
+
ActiveSupport.on_load(:action_view) do
|
4
|
+
include PrettyWeather
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer 'pretty_weather.configuration' do |app|
|
9
|
+
app.config.pretty_weather = PrettyWeather::Configuration.new
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module PrettyWeather
|
5
|
+
class Weather
|
6
|
+
attr_accessor :temp, :weather, :icon_tag, :temp_numeric, :city_name, :units, :updated_at
|
7
|
+
|
8
|
+
def initialize(city_name, units)
|
9
|
+
@city_name = city_name
|
10
|
+
@units = units
|
11
|
+
|
12
|
+
collect_data(city_name, units)
|
13
|
+
end
|
14
|
+
|
15
|
+
def collect_data(city_name = @city_name, units = @units)
|
16
|
+
link = "http://api.openweathermap.org/data/2.5/weather?q=#{city_name}&mode=xml&units=#{units}" #Odesa for Odessa in Ukraine
|
17
|
+
attempts = 3
|
18
|
+
|
19
|
+
@updated_at = Time.now
|
20
|
+
|
21
|
+
begin
|
22
|
+
data = Nokogiri::XML(open(link))
|
23
|
+
|
24
|
+
@temp_numeric = data.xpath('//temperature')[0]['value'].to_f
|
25
|
+
|
26
|
+
@temp = data.xpath('//temperature')[0]['value'].to_i.to_s
|
27
|
+
weather_code = data.xpath('//weather')[0]['icon']
|
28
|
+
|
29
|
+
@temp = "+#{@temp}" unless @temp.index('-')
|
30
|
+
@weather = weather_name(weather_code)
|
31
|
+
|
32
|
+
@icon_tag = select_weather_icon @weather
|
33
|
+
rescue OpenURI::HTTPError => e
|
34
|
+
attempts -= 1
|
35
|
+
retry unless attempts.zero?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def weather_name(weather_code)
|
40
|
+
case weather_code
|
41
|
+
when '01d'
|
42
|
+
'sunny'
|
43
|
+
when '01n'
|
44
|
+
'moonly'
|
45
|
+
when '02d'
|
46
|
+
'day_cloud'
|
47
|
+
when '02n'
|
48
|
+
'night_cloud'
|
49
|
+
when '50d', '50n'
|
50
|
+
'foggy'
|
51
|
+
when '10d'
|
52
|
+
'day_rain'
|
53
|
+
when '10n'
|
54
|
+
'night_rain'
|
55
|
+
when '09d', '09n'
|
56
|
+
'heavy_rain'
|
57
|
+
when '13d', '13n'
|
58
|
+
'snow'
|
59
|
+
when '11d', '11n'
|
60
|
+
'thunder'
|
61
|
+
when '03d', '03n', '04d', '04n'
|
62
|
+
'cloud'
|
63
|
+
else
|
64
|
+
'good'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def select_weather_icon(weather)
|
69
|
+
icon = case weather
|
70
|
+
when 'sunny'
|
71
|
+
'<i class="wi wi-day-sunny"></i>'
|
72
|
+
when 'moonly'
|
73
|
+
'<i class="wi wi-night-clear"></i>'
|
74
|
+
when 'day_cloud'
|
75
|
+
'<i class="wi wi-day-cloudy"></i>'
|
76
|
+
when 'night_cloud'
|
77
|
+
'<i class="wi wi-night-alt-cloudy"></i>'
|
78
|
+
when 'foggy'
|
79
|
+
'<i class="wi wi-dust"></i>'
|
80
|
+
when 'day_rain'
|
81
|
+
'<i class="wi wi-day-showers"></i>'
|
82
|
+
when 'night_rain'
|
83
|
+
'<i class="wi wi-night-alt-sprinkle"></i>'
|
84
|
+
when 'heavy_rain'
|
85
|
+
'<i class="wi wi-sprinkle"></i>'
|
86
|
+
when 'windy'
|
87
|
+
'<i class="wi wi-cloudy-gusts"></i>'
|
88
|
+
when 'snow'
|
89
|
+
'<i class="wi wi-snow"></i>'
|
90
|
+
when 'thunder'
|
91
|
+
'<i class="wi wi-thunderstorm"></i>'
|
92
|
+
when 'cloud'
|
93
|
+
'<i class="wi wi-cloudy"></i>'
|
94
|
+
when 'good'
|
95
|
+
'<i class="wi wi-thermometer-exterior"></i>'
|
96
|
+
else
|
97
|
+
'<i class="wi wi-cloud-refresh"></i>'
|
98
|
+
end
|
99
|
+
icon.html_safe
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'pretty_weather'
|
4
|
+
|
5
|
+
class PrettyWeatherTest < ActiveSupport::TestCase
|
6
|
+
setup do
|
7
|
+
@weather = PrettyWeather::Weather.new('odesa', 'metric')
|
8
|
+
end
|
9
|
+
|
10
|
+
test "truth" do
|
11
|
+
assert_kind_of Module, PrettyWeather
|
12
|
+
end
|
13
|
+
|
14
|
+
test "weather_temp_should_be_a_number" do
|
15
|
+
assert_kind_of String, @weather.temp
|
16
|
+
end
|
17
|
+
|
18
|
+
test "weather_state_should_be_not_less_than_four_length_string" do
|
19
|
+
assert_kind_of String, @weather.weather
|
20
|
+
assert @weather.weather.length >= 4
|
21
|
+
end
|
22
|
+
|
23
|
+
test "weather_icon_should_be_a_string_with_tag_i" do
|
24
|
+
assert_kind_of String, @weather.icon_tag
|
25
|
+
assert @weather.icon_tag.index('<i') >= 0
|
26
|
+
assert @weather.icon_tag.index('</i>') >= 0
|
27
|
+
end
|
28
|
+
|
29
|
+
test "collect_weather_should_update_weather_state" do
|
30
|
+
old_time = @weather.updated_at
|
31
|
+
|
32
|
+
@weather.collect_data
|
33
|
+
new_time = @weather.updated_at
|
34
|
+
|
35
|
+
assert_not_equal old_time, new_time
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
# Load fixtures from the engine
|
13
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pretty_weather
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- NikitaSmall
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: weather-icons-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Pretty_weather is a gem for easy implementation for openweather api with
|
70
|
+
pretty icons for current weather at specific location
|
71
|
+
email:
|
72
|
+
- nikitasosnov@yahoo.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- MIT-LICENSE
|
78
|
+
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- lib/pretty_weather.rb
|
81
|
+
- lib/pretty_weather/configuration.rb
|
82
|
+
- lib/pretty_weather/engine.rb
|
83
|
+
- lib/pretty_weather/pretty_weather_helper.rb
|
84
|
+
- lib/pretty_weather/railtie.rb
|
85
|
+
- lib/pretty_weather/version.rb
|
86
|
+
- lib/pretty_weather/weather.rb
|
87
|
+
- lib/tasks/pretty_weather_tasks.rake
|
88
|
+
- test/pretty_weather_test.rb
|
89
|
+
- test/test_helper.rb
|
90
|
+
homepage: https://github.com/NikitaSmall/pretty_weather
|
91
|
+
licenses: []
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Gem for easy implementation for openweather api
|
113
|
+
test_files:
|
114
|
+
- test/pretty_weather_test.rb
|
115
|
+
- test/test_helper.rb
|