tropical 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +101 -8
- data/lib/tropical.rb +45 -30
- data/lib/tropical/version.rb +1 -1
- data/tropical.gemspec +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a02e1d2772e6ea9d2d5cfe3238daf51e7880e0e47aa4ea93b80bf06e99c86868
|
|
4
|
+
data.tar.gz: c9f2fb4a9d13e10a6bfd12eea9b1671190068a75f019ae8330782eea269d8c79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e5cc4b58e8b16e6dfbfae6c4d575688bedca5ea6f32c789f49c55af29ddb9550ac4bdd2171aebfc15b245fe614c885392fecd8da31a944bc1db93a7ee12d4c9
|
|
7
|
+
data.tar.gz: f70a42ff3bd9092a81aa41e4842ec1b1af0416227d45de1561b6e0514af92604cc9bb56f7fdda88ee7f8466b1ee12c1d4c90a08e2740f5d6ff27126780aaa758
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
# Tropical
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
|
3
|
+
Gem to consultation weather forecast up to 5 days.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
7
|
Add this line to your application's Gemfile:
|
|
10
8
|
|
|
11
9
|
```ruby
|
|
12
|
-
gem 'tropical', '~> 0.1.
|
|
13
|
-
|
|
14
|
-
# or
|
|
15
|
-
gem 'tropical', git: 'https://github.com/valterandrei/tropical', branch: 'main'
|
|
10
|
+
gem 'tropical', '~> 0.1.8'
|
|
16
11
|
```
|
|
17
12
|
|
|
18
13
|
And then execute:
|
|
@@ -21,7 +16,105 @@ And then execute:
|
|
|
21
16
|
|
|
22
17
|
## Usage
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
Ruby API
|
|
20
|
+
```ruby
|
|
21
|
+
tropical = Tropical::OpenWeatherMap.new(
|
|
22
|
+
{
|
|
23
|
+
appid: 'your_api_key', # required
|
|
24
|
+
q: 'São Paulo', # required
|
|
25
|
+
lang: 'pt_br', # optional
|
|
26
|
+
units: 'metric', # optional
|
|
27
|
+
cnt: '50' # optional
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
For more information about the params: [openweathermap](https://openweathermap.org/forecast5)
|
|
32
|
+
|
|
33
|
+
Note: The `mode` param is not avaible.
|
|
34
|
+
|
|
35
|
+
- City name
|
|
36
|
+
```ruby
|
|
37
|
+
tropical.city_name
|
|
38
|
+
|
|
39
|
+
# => "São Paulo"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Population
|
|
43
|
+
```ruby
|
|
44
|
+
tropical.population
|
|
45
|
+
|
|
46
|
+
# => 10021295
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Country
|
|
50
|
+
```ruby
|
|
51
|
+
tropical.country
|
|
52
|
+
|
|
53
|
+
# => "BR"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- Timezone
|
|
57
|
+
```ruby
|
|
58
|
+
tropical.timezone
|
|
59
|
+
|
|
60
|
+
# => -3
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- Current date
|
|
64
|
+
```ruby
|
|
65
|
+
tropical.current_date
|
|
66
|
+
|
|
67
|
+
# => 2021-02-14 18:00:00 -0300
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- Coord
|
|
71
|
+
```ruby
|
|
72
|
+
tropical.coord
|
|
73
|
+
|
|
74
|
+
# => {:lat=>-23.5475, :lon=>-46.6361}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- Scale
|
|
78
|
+
```ruby
|
|
79
|
+
tropical.scale
|
|
80
|
+
|
|
81
|
+
# => "°C"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- Current temperature
|
|
85
|
+
```ruby
|
|
86
|
+
tropical.current_temp
|
|
87
|
+
|
|
88
|
+
# => 26.92
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- Current weather
|
|
92
|
+
```ruby
|
|
93
|
+
tropical.current_weather
|
|
94
|
+
|
|
95
|
+
# => "chuva moderada"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- Full sumary
|
|
99
|
+
```ruby
|
|
100
|
+
tropical.full_sumary
|
|
101
|
+
|
|
102
|
+
# => "27°C e chuva moderada em São Paulo em 14/02. Média para os próximos dias: 26°C em 14/02, 26°C em 15/02, 26°C em 16/02, 26°C em 17/02, 25°C em 18/02 e 24°C em 19/02."
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- Sumary current day
|
|
106
|
+
```ruby
|
|
107
|
+
tropical.sumary_current_day
|
|
108
|
+
|
|
109
|
+
# => "27°C e chuva moderada em São Paulo em 14/02."
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- Sumary days forecast
|
|
113
|
+
```ruby
|
|
114
|
+
tropical.sumary_days_forecast
|
|
115
|
+
|
|
116
|
+
# => "26°C em 14/02, 26°C em 15/02, 26°C em 16/02, 26°C em 17/02, 25°C em 18/02 e 24°C em 19/02."
|
|
117
|
+
```
|
|
25
118
|
|
|
26
119
|
## Development
|
|
27
120
|
|
data/lib/tropical.rb
CHANGED
|
@@ -18,10 +18,26 @@ module Tropical
|
|
|
18
18
|
load_data(response)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def
|
|
21
|
+
def city_name
|
|
22
22
|
data["city"]["name"]
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
def country
|
|
26
|
+
data["city"]["country"]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def population
|
|
30
|
+
data["city"]["population"]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def timezone
|
|
34
|
+
Time.at(data["city"]["timezone"]).zone.to_i
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def coord
|
|
38
|
+
data["city"]["coord"].transform_keys(&:to_sym)
|
|
39
|
+
end
|
|
40
|
+
|
|
25
41
|
def current_date
|
|
26
42
|
list.first[:dt]
|
|
27
43
|
end
|
|
@@ -51,7 +67,7 @@ module Tropical
|
|
|
51
67
|
|
|
52
68
|
def sumary_current_day
|
|
53
69
|
"#{current_temp.round}#{scale} e #{current_weather} em "\
|
|
54
|
-
"#{
|
|
70
|
+
"#{city_name} em #{current_date.strftime("%d/%m")}."
|
|
55
71
|
end
|
|
56
72
|
|
|
57
73
|
def sumary_days_forecast
|
|
@@ -62,45 +78,21 @@ module Tropical
|
|
|
62
78
|
"#{list.to_sentence(words_connector: ", ", last_word_connector: " e ")}."
|
|
63
79
|
end
|
|
64
80
|
|
|
65
|
-
def list
|
|
66
|
-
data["list"].map do |list_item|
|
|
67
|
-
{
|
|
68
|
-
dt: Time.at(list_item["dt"]),
|
|
69
|
-
temp: list_item["main"]["temp"],
|
|
70
|
-
description: list_item["weather"].first["description"]
|
|
71
|
-
}
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def average_temp_by_days
|
|
76
|
-
group_by_days = list.group_by { |item| item[:dt].to_date }
|
|
77
|
-
days = []
|
|
78
|
-
|
|
79
|
-
group_by_days.each do |day, temps|
|
|
80
|
-
average = temps.sum { |time| time[:temp] } / temps.length
|
|
81
|
-
|
|
82
|
-
days << { day: day, average: average.round }
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
days
|
|
86
|
-
end
|
|
87
|
-
|
|
88
81
|
private
|
|
89
82
|
|
|
90
83
|
def request_params
|
|
91
84
|
link = ""
|
|
92
85
|
|
|
93
86
|
params.each do |k, v|
|
|
94
|
-
|
|
87
|
+
next if k == :mode
|
|
88
|
+
next unless v.is_a?(String) && v.present?
|
|
89
|
+
|
|
90
|
+
link += "&#{k}=#{I18n.transliterate(v)}"
|
|
95
91
|
end
|
|
96
92
|
|
|
97
93
|
BASE_URL + link
|
|
98
94
|
end
|
|
99
95
|
|
|
100
|
-
def remove_accents(value)
|
|
101
|
-
I18n.transliterate(value)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
96
|
def load_data(response)
|
|
105
97
|
@status = response.code
|
|
106
98
|
@data = case response
|
|
@@ -113,6 +105,29 @@ module Tropical
|
|
|
113
105
|
end
|
|
114
106
|
end
|
|
115
107
|
|
|
108
|
+
def average_temp_by_days
|
|
109
|
+
group_by_days = list.group_by { |item| item[:dt].to_date }
|
|
110
|
+
days = []
|
|
111
|
+
|
|
112
|
+
group_by_days.each do |day, temps|
|
|
113
|
+
average = temps.sum { |time| time[:temp] } / temps.length
|
|
114
|
+
|
|
115
|
+
days << { day: day, average: average.round }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
days
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def list
|
|
122
|
+
data["list"].map do |list_item|
|
|
123
|
+
{
|
|
124
|
+
dt: Time.at(list_item["dt"]),
|
|
125
|
+
temp: list_item["main"]["temp"],
|
|
126
|
+
description: list_item["weather"].first["description"]
|
|
127
|
+
}
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
116
131
|
def post(request_params)
|
|
117
132
|
url = URI(request_params)
|
|
118
133
|
http = Net::HTTP.new(url.host, url.port)
|
data/lib/tropical/version.rb
CHANGED
data/tropical.gemspec
CHANGED
|
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
28
28
|
spec.require_paths = ["lib"]
|
|
29
29
|
|
|
30
|
-
# Uncomment to register a new dependency of your gem
|
|
31
30
|
spec.add_dependency "activesupport", "~> 6.1.2.1"
|
|
32
31
|
|
|
33
32
|
# For more information and examples about making a new gem, checkout our
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tropical
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Valter
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-02-
|
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|