tropical 0.1.1 → 0.1.6
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/CODE_OF_CONDUCT.md +0 -2
- data/Gemfile.lock +15 -1
- data/README.md +4 -1
- data/lib/tropical.rb +51 -18
- data/lib/tropical/version.rb +1 -1
- data/tropical.gemspec +1 -2
- metadata +17 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 951846b67756ef790d084887e5656c8073d78ca755a8503807ad99a283afdb5d
|
|
4
|
+
data.tar.gz: a56eeb6e6d44724aacfc237fbd3a1d0d82a9d688c429ba6c971794a5bcf445c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9b99a891cc45d53c9dce81d02ef5356ee972bbfca519240d4ef7234bdd5fe6b84810240b37a352ad56bb105482cbdf88aa72f6051b4bb0e3eaeb56e8a996405
|
|
7
|
+
data.tar.gz: ba09b867c7ea1dc302d2573cf0190205611667a7a83069107a648a49040d99c37a24ffed0ffc51bab23081397b8cee45631b68de6ea8c30f8b63f7694697cae1
|
data/CODE_OF_CONDUCT.md
CHANGED
|
@@ -69,8 +69,6 @@ Community leaders will follow these Community Impact Guidelines in determining t
|
|
|
69
69
|
|
|
70
70
|
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
71
71
|
|
|
72
|
-
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
|
73
|
-
|
|
74
72
|
## Attribution
|
|
75
73
|
|
|
76
74
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
tropical (0.1.
|
|
4
|
+
tropical (0.1.6)
|
|
5
|
+
activesupport (~> 6.1.2.1)
|
|
5
6
|
|
|
6
7
|
GEM
|
|
7
8
|
remote: https://rubygems.org/
|
|
8
9
|
specs:
|
|
10
|
+
activesupport (6.1.2.1)
|
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
12
|
+
i18n (>= 1.6, < 2)
|
|
13
|
+
minitest (>= 5.1)
|
|
14
|
+
tzinfo (~> 2.0)
|
|
15
|
+
zeitwerk (~> 2.3)
|
|
9
16
|
ast (2.4.2)
|
|
17
|
+
concurrent-ruby (1.1.8)
|
|
10
18
|
diff-lcs (1.4.4)
|
|
19
|
+
i18n (1.8.9)
|
|
20
|
+
concurrent-ruby (~> 1.0)
|
|
21
|
+
minitest (5.14.3)
|
|
11
22
|
parallel (1.20.1)
|
|
12
23
|
parser (3.0.0.0)
|
|
13
24
|
ast (~> 2.4.1)
|
|
@@ -40,7 +51,10 @@ GEM
|
|
|
40
51
|
rubocop-ast (1.4.1)
|
|
41
52
|
parser (>= 2.7.1.5)
|
|
42
53
|
ruby-progressbar (1.11.0)
|
|
54
|
+
tzinfo (2.0.4)
|
|
55
|
+
concurrent-ruby (~> 1.0)
|
|
43
56
|
unicode-display_width (2.0.0)
|
|
57
|
+
zeitwerk (2.4.2)
|
|
44
58
|
|
|
45
59
|
PLATFORMS
|
|
46
60
|
x86_64-linux
|
data/README.md
CHANGED
data/lib/tropical.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "active_support/all"
|
|
1
2
|
require "date"
|
|
2
3
|
require "json"
|
|
3
4
|
require "net/http"
|
|
@@ -7,30 +8,21 @@ module Tropical
|
|
|
7
8
|
class OpenWeatherMap
|
|
8
9
|
BASE_URL = "https://api.openweathermap.org/data/2.5/forecast?".freeze
|
|
9
10
|
|
|
10
|
-
attr_reader :data, :status
|
|
11
|
+
attr_reader :data, :params, :status
|
|
11
12
|
|
|
12
13
|
def initialize(params)
|
|
13
|
-
|
|
14
|
-
response
|
|
14
|
+
@params = params
|
|
15
|
+
response = post(request_params)
|
|
15
16
|
|
|
16
17
|
load_data(response)
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
days = []
|
|
22
|
-
|
|
23
|
-
group_by_days.each do |day, temps|
|
|
24
|
-
average = temps.sum { |time| time[:temp] } / temps.length
|
|
25
|
-
|
|
26
|
-
days << { day: day, average: average.round }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
days
|
|
20
|
+
def city
|
|
21
|
+
data["city"]["name"]
|
|
30
22
|
end
|
|
31
23
|
|
|
32
24
|
def current_date
|
|
33
|
-
list.first[:
|
|
25
|
+
list.first[:dt]
|
|
34
26
|
end
|
|
35
27
|
|
|
36
28
|
def current_temp
|
|
@@ -41,23 +33,64 @@ module Tropical
|
|
|
41
33
|
list.first[:description]
|
|
42
34
|
end
|
|
43
35
|
|
|
36
|
+
def scale
|
|
37
|
+
units = params[:units]
|
|
38
|
+
|
|
39
|
+
return "°C" if units == "metric"
|
|
40
|
+
return "°F" if units == "imperial"
|
|
41
|
+
|
|
42
|
+
"°K"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def full_sumary
|
|
46
|
+
"#{sumary_current_day} "\
|
|
47
|
+
"Média para os próximos dias: "\
|
|
48
|
+
"#{sumary_days_forecast}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def sumary_current_day
|
|
52
|
+
"#{current_temp.round}#{scale} e #{current_weather} em "\
|
|
53
|
+
"#{city} em #{current_date.strftime("%d/%m")}."
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def sumary_days_forecast
|
|
57
|
+
list = average_temp_by_days.map do |x|
|
|
58
|
+
"#{x[:average]}#{scale} em #{x[:day].strftime("%d/%m")}"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
"#{list.to_sentence(words_connector: ", ", last_word_connector: " e ")}."
|
|
62
|
+
end
|
|
63
|
+
|
|
44
64
|
def list
|
|
45
65
|
data["list"].map do |list_item|
|
|
46
66
|
{
|
|
47
|
-
|
|
67
|
+
dt: Time.zone.at(list_item["dt"]),
|
|
48
68
|
temp: list_item["main"]["temp"],
|
|
49
69
|
description: list_item["weather"].first["description"]
|
|
50
70
|
}
|
|
51
71
|
end
|
|
52
72
|
end
|
|
53
73
|
|
|
74
|
+
def average_temp_by_days
|
|
75
|
+
group_by_days = list.group_by { |item| item[:dt].to_date }
|
|
76
|
+
days = []
|
|
77
|
+
|
|
78
|
+
group_by_days.each do |day, temps|
|
|
79
|
+
average = temps.sum { |time| time[:temp] } / temps.length
|
|
80
|
+
|
|
81
|
+
days << { day: day, average: average.round }
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
days
|
|
85
|
+
end
|
|
86
|
+
|
|
54
87
|
private
|
|
55
88
|
|
|
56
|
-
def
|
|
89
|
+
def request_params
|
|
57
90
|
link = ""
|
|
58
91
|
|
|
59
92
|
params.each do |k, v|
|
|
60
|
-
link += "&#{k}=#{v}" if v.is_a?(String) &&
|
|
93
|
+
link += "&#{k}=#{v}" if v.is_a?(String) && v.present?
|
|
61
94
|
end
|
|
62
95
|
|
|
63
96
|
BASE_URL + link
|
data/lib/tropical/version.rb
CHANGED
data/tropical.gemspec
CHANGED
|
@@ -14,7 +14,6 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
|
15
15
|
|
|
16
16
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
17
|
-
|
|
18
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
18
|
spec.metadata["source_code_uri"] = "https://github.com/ValterAndrei/tropical"
|
|
20
19
|
spec.metadata["changelog_uri"] = "https://github.com/ValterAndrei/tropical"
|
|
@@ -29,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
|
29
28
|
spec.require_paths = ["lib"]
|
|
30
29
|
|
|
31
30
|
# Uncomment to register a new dependency of your gem
|
|
32
|
-
|
|
31
|
+
spec.add_dependency "activesupport", "~> 6.1.2.1"
|
|
33
32
|
|
|
34
33
|
# For more information and examples about making a new gem, checkout our
|
|
35
34
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
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.6
|
|
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-
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2021-02-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 6.1.2.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 6.1.2.1
|
|
13
27
|
description: Consultation weather forecast up to 5 days.
|
|
14
28
|
email:
|
|
15
29
|
- valterandrey@gmail.com
|