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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a59d99f2cdba910fc0727756cefd35ed148866951c4087484b964de2dc9b49e
4
- data.tar.gz: a31cb9bb5c5232579d88669ef08ac2776869ead0a4aaf928af633bdd47bd899e
3
+ metadata.gz: 951846b67756ef790d084887e5656c8073d78ca755a8503807ad99a283afdb5d
4
+ data.tar.gz: a56eeb6e6d44724aacfc237fbd3a1d0d82a9d688c429ba6c971794a5bcf445c0
5
5
  SHA512:
6
- metadata.gz: 9548089ca4fd3568ffd896a77ad5399df38052239f368e90e817365acfe7f4cbbb062da0a13a0434fcc1a415213bfced3c162e4e53fd7d3376789e459ce0c18d
7
- data.tar.gz: 01f0637079f837719575ea9485a47d4039e00f8c87592f5b8f5f9c53a26c1b36e7fd3f9247db02541f02a49693563fcd9ae45316b7ca980496d8753863d5b32b
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.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
@@ -8,7 +8,10 @@ TODO: Delete this and the text above, and describe your gem
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- ```rails
11
+ ```ruby
12
+ gem 'tropical'
13
+
14
+ # or
12
15
  gem 'tropical', git: 'https://github.com/valterandrei/tropical', branch: 'main'
13
16
  ```
14
17
 
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
- request_params = build_request_params(params)
14
- response = post(request_params)
14
+ @params = params
15
+ response = post(request_params)
15
16
 
16
17
  load_data(response)
17
18
  end
18
19
 
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
20
+ def city
21
+ data["city"]["name"]
30
22
  end
31
23
 
32
24
  def current_date
33
- list.first[:datetime]
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
- datetime: Time.at(list_item["dt"]),
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 build_request_params(params)
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) && !v.empty?
93
+ link += "&#{k}=#{v}" if v.is_a?(String) && v.present?
61
94
  end
62
95
 
63
96
  BASE_URL + link
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tropical
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.6"
5
5
  end
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
- # spec.add_dependency "example-gem", "~> 1.0"
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.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-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