tropical 0.1.2 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad251438dd31911fd226055004c5966f7df86fd59afe32db172f3742126e04b0
4
- data.tar.gz: 8c65872a8138270b0e9f393315b004dba919c7504054321865d560652146d4cc
3
+ metadata.gz: 05adf7476cd249260bbd78ebbcdb5bc373b9da5a052121781f3fbdd4095d54ae
4
+ data.tar.gz: 965f99ee0e06962426e6608b4516e56e334787b7c6a8f3256d298e55d6a81193
5
5
  SHA512:
6
- metadata.gz: 7d2648038b21a0e51dcca5e14936c772c695bcce9902632e54d0c8807ab481d7e8bc38db64ef9c953756933778b1b106b9085d971df13b3ea090da4bf1c7025a
7
- data.tar.gz: 1b44a54bf7ce7f44d64d96920eee0d4222bcfdd2e37a4d2de5a5596260598d9dd03cba6f99889338a1414f59d4c0be624049f0588f357ed647e3df59c1a39928
6
+ metadata.gz: cf882a35685811adc116fdfac3012c36147860fe1ba3e68346b68b979c4cb3999a2fc67376cdf76799d3383bf42df64e5553f2f3962dd9fe44a013b17afca212
7
+ data.tar.gz: f54f6bf544e22bc3afaac54259f7819af1d79987e65609bdf84fabb398db4838b95d5a11d7c7d9c4cfa0110252d3c8b4d63c291b4076c714cfa0f8cdf6d5dabe
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.2)
4
+ tropical (0.1.7)
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
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'tropical'
12
+ gem 'tropical', '~> 0.1.7'
13
13
 
14
14
  # or
15
15
  gem 'tropical', git: 'https://github.com/valterandrei/tropical', branch: 'main'
data/lib/tropical.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require "active_support/all"
1
2
  require "date"
2
3
  require "json"
4
+ require "i18n"
3
5
  require "net/http"
4
6
  require "uri"
5
7
 
@@ -7,34 +9,21 @@ module Tropical
7
9
  class OpenWeatherMap
8
10
  BASE_URL = "https://api.openweathermap.org/data/2.5/forecast?".freeze
9
11
 
10
- attr_reader :data, :status
12
+ attr_reader :data, :params, :status
11
13
 
12
14
  def initialize(params)
13
- request_params = build_request_params(params)
14
- response = post(request_params)
15
+ @params = params
16
+ response = post(request_params)
15
17
 
16
18
  load_data(response)
17
19
  end
18
20
 
19
- def average_temp_by_days
20
- group_by_days = list.group_by { |item| item[:datetime].to_date }
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
30
- end
31
-
32
21
  def city
33
22
  data["city"]["name"]
34
23
  end
35
24
 
36
25
  def current_date
37
- list.first[:datetime]
26
+ list.first[:dt]
38
27
  end
39
28
 
40
29
  def current_temp
@@ -45,28 +34,73 @@ module Tropical
45
34
  list.first[:description]
46
35
  end
47
36
 
37
+ def scale
38
+ units = params[:units]
39
+
40
+ return "°C" if units == "metric"
41
+ return "°F" if units == "imperial"
42
+
43
+ "°K"
44
+ end
45
+
46
+ def full_sumary
47
+ "#{sumary_current_day} "\
48
+ "Média para os próximos dias: "\
49
+ "#{sumary_days_forecast}"
50
+ end
51
+
52
+ def sumary_current_day
53
+ "#{current_temp.round}#{scale} e #{current_weather} em "\
54
+ "#{city} em #{current_date.strftime("%d/%m")}."
55
+ end
56
+
57
+ def sumary_days_forecast
58
+ list = average_temp_by_days.map do |x|
59
+ "#{x[:average]}#{scale} em #{x[:day].strftime("%d/%m")}"
60
+ end
61
+
62
+ "#{list.to_sentence(words_connector: ", ", last_word_connector: " e ")}."
63
+ end
64
+
48
65
  def list
49
66
  data["list"].map do |list_item|
50
67
  {
51
- datetime: Time.at(list_item["dt"]),
68
+ dt: Time.at(list_item["dt"]),
52
69
  temp: list_item["main"]["temp"],
53
70
  description: list_item["weather"].first["description"]
54
71
  }
55
72
  end
56
73
  end
57
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
+
58
88
  private
59
89
 
60
- def build_request_params(params)
90
+ def request_params
61
91
  link = ""
62
92
 
63
93
  params.each do |k, v|
64
- link += "&#{k}=#{v}" if v.is_a?(String) && !v.empty?
94
+ link += "&#{k}=#{remove_accents(v)}" if v.is_a?(String) && v.present?
65
95
  end
66
96
 
67
97
  BASE_URL + link
68
98
  end
69
99
 
100
+ def remove_accents(value)
101
+ I18n.transliterate(value)
102
+ end
103
+
70
104
  def load_data(response)
71
105
  @status = response.code
72
106
  @data = case response
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tropical
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.7"
5
5
  end
data/tropical.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  # Uncomment to register a new dependency of your gem
31
- # spec.add_dependency "example-gem", "~> 1.0"
31
+ spec.add_dependency "activesupport", "~> 6.1.2.1"
32
32
 
33
33
  # For more information and examples about making a new gem, checkout our
34
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.2
4
+ version: 0.1.7
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-13 00:00:00.000000000 Z
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