tropical 0.1.4 → 0.1.9

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: 953aca22adc93a3af8f07baa5e168a61c6e40d23731ce2df5bc25f7e0b3c2878
4
- data.tar.gz: ea6d4bacb6cb117b354a670e4334d7d26f1f154d9c1844d99a3156f46e6282d9
3
+ metadata.gz: e476e340003d8dbeddffadbac3a5b832ec2de83e3b74fb188c4caf8bd9e69332
4
+ data.tar.gz: 8817fa2177338c740cedbf4089eefc47e768bb59192467bb090aa9a67b2de978
5
5
  SHA512:
6
- metadata.gz: 0a5e95d3d0be81e1ac048d6f8c23bc4bfd39217024d91d0b346b1d673e7deb748abff6ac970c2b9f41fea6968930037436656eaa6a16b78ec78ac9b7a3078185
7
- data.tar.gz: fd59c9c81c0da541ba21a4fe30d8fd437cce0c8940f92694e87bf76222d405b9fddee4f28e0a656064f094efe7d2893cbff9b7eedbef39d8560e94b1401e1a67
6
+ metadata.gz: 0142d337b7ec7dda644e3803dd74f401aa7f1d8df818fc242dac7ff0e3be09e34a3d16b2f043102661cf0d1b736d0ba57c74d504e15fb590933796ffc87fceaa
7
+ data.tar.gz: 6eaa1019d4d085d66e3802555ca1333d94dcac28a1eb1bf7cbd1b5f88875a14c807da8c1f9981615123ab60b2adce6fff2af376f77d31582ed4034c690ad7a00
@@ -0,0 +1,40 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ teste-ci ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 2.6
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.6.x
18
+
19
+ - name: Publish to GPR
20
+ run: |
21
+ mkdir -p $HOME/.gem
22
+ touch $HOME/.gem/credentials
23
+ chmod 0600 $HOME/.gem/credentials
24
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
25
+ gem build *.gemspec
26
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
27
+ env:
28
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
29
+ OWNER: ${{ github.repository_owner }}
30
+
31
+ - name: Publish to RubyGems
32
+ run: |
33
+ mkdir -p $HOME/.gem
34
+ touch $HOME/.gem/credentials
35
+ chmod 0600 $HOME/.gem/credentials
36
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
37
+ gem build *.gemspec
38
+ gem push *.gem
39
+ env:
40
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/CODE_OF_CONDUCT.md CHANGED
@@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when
39
39
 
40
40
  ## Enforcement
41
41
 
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at valter.sandoval@redealumni.com. All complaints will be reviewed and investigated promptly and fairly.
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at valterandrey@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
43
 
44
44
  All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
45
 
@@ -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)
4
+ tropical (0.1.9)
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
@@ -1,18 +1,13 @@
1
1
  # Tropical
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tropical`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Gem to search weather forecast for 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'
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
- TODO: Write usage instructions here
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
 
@@ -31,8 +124,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
31
124
 
32
125
  ## Contributing
33
126
 
34
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tropical. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/tropical/blob/master/CODE_OF_CONDUCT.md).
127
+ Bug reports and pull requests are welcome on GitHub at https://github.com/valterandrei/tropical. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ValterAndrei/tropical/blob/main/CODE_OF_CONDUCT.md).
35
128
 
36
129
  ## Code of Conduct
37
130
 
38
- Everyone interacting in the Tropical project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tropical/blob/master/CODE_OF_CONDUCT.md).
131
+ Everyone interacting in the Tropical project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ValterAndrei/tropical/blob/main/CODE_OF_CONDUCT.md).
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
 
@@ -16,25 +18,28 @@ module Tropical
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 = []
21
+ def city_name
22
+ data["city"]["name"]
23
+ end
22
24
 
23
- group_by_days.each do |day, temps|
24
- average = temps.sum { |time| time[:temp] } / temps.length
25
+ def country
26
+ data["city"]["country"]
27
+ end
25
28
 
26
- days << { day: day, average: average.round }
27
- end
29
+ def population
30
+ data["city"]["population"]
31
+ end
28
32
 
29
- days
33
+ def timezone
34
+ Time.at(data["city"]["timezone"]).zone.to_i
30
35
  end
31
36
 
32
- def city
33
- data["city"]["name"]
37
+ def coord
38
+ data["city"]["coord"].transform_keys(&:to_sym)
34
39
  end
35
40
 
36
41
  def current_date
37
- list.first[:datetime]
42
+ list.first[:dt]
38
43
  end
39
44
 
40
45
  def current_temp
@@ -45,16 +50,6 @@ module Tropical
45
50
  list.first[:description]
46
51
  end
47
52
 
48
- def list
49
- data["list"].map do |list_item|
50
- {
51
- datetime: Time.at(list_item["dt"]),
52
- temp: list_item["main"]["temp"],
53
- description: list_item["weather"].first["description"]
54
- }
55
- end
56
- end
57
-
58
53
  def scale
59
54
  units = params[:units]
60
55
 
@@ -64,16 +59,23 @@ module Tropical
64
59
  "°K"
65
60
  end
66
61
 
67
- def sumary
68
- message = format_message
69
-
70
- "#{message.current_temp}#{scale} e #{current_weather} em #{city} em #{message.current_date}. "\
62
+ def full_sumary
63
+ "#{sumary_current_day} "\
71
64
  "Média para os próximos dias: "\
72
- "#{message.first_day_average}#{scale} em #{message.first_day_date}, "\
73
- "#{message.second_day_average}#{scale} em #{message.second_day_date}, "\
74
- "#{message.third_day_average}#{scale} em #{message.third_day_date}, "\
75
- "#{message.fourth_day_average}#{scale} em #{message.fourth_day_date} "\
76
- "e #{message.fifth_day_average}#{scale} em #{message.fifth_day_date}."
65
+ "#{sumary_days_forecast}"
66
+ end
67
+
68
+ def sumary_current_day
69
+ "#{current_temp.round}#{scale} e #{current_weather} em "\
70
+ "#{city_name} em #{current_date.strftime("%d/%m")}."
71
+ end
72
+
73
+ def sumary_days_forecast
74
+ list = average_temp_by_days.map do |x|
75
+ "#{x[:average]}#{scale} em #{x[:day].strftime("%d/%m")}"
76
+ end
77
+
78
+ "#{list.to_sentence(words_connector: ", ", last_word_connector: " e ")}."
77
79
  end
78
80
 
79
81
  private
@@ -82,29 +84,15 @@ module Tropical
82
84
  link = ""
83
85
 
84
86
  params.each do |k, v|
85
- link += "&#{k}=#{v}" if v.is_a?(String) && !v.empty?
87
+ next if k == :mode
88
+ next unless v.is_a?(String) && v.present?
89
+
90
+ link += "&#{k}=#{I18n.transliterate(v)}"
86
91
  end
87
92
 
88
93
  BASE_URL + link
89
94
  end
90
95
 
91
- def format_message
92
- OpenStruct.new(
93
- current_temp: current_temp.round,
94
- current_date: current_date.strftime("%d/%m"),
95
- first_day_average: average_temp_by_days[0][:average],
96
- first_day_date: average_temp_by_days[0][:day].strftime("%d/%m"),
97
- second_day_average: average_temp_by_days[1][:average],
98
- second_day_date: average_temp_by_days[1][:day].strftime("%d/%m"),
99
- third_day_average: average_temp_by_days[2][:average],
100
- third_day_date: average_temp_by_days[2][:day].strftime("%d/%m"),
101
- fourth_day_average: average_temp_by_days[3][:average],
102
- fourth_day_date: average_temp_by_days[3][:day].strftime("%d/%m"),
103
- fifth_day_average: average_temp_by_days[4][:average],
104
- fifth_day_date: average_temp_by_days[4][:day].strftime("%d/%m")
105
- )
106
- end
107
-
108
96
  def load_data(response)
109
97
  @status = response.code
110
98
  @data = case response
@@ -117,6 +105,29 @@ module Tropical
117
105
  end
118
106
  end
119
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
+
120
131
  def post(request_params)
121
132
  url = URI(request_params)
122
133
  http = Net::HTTP.new(url.host, url.port)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tropical
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.9"
5
5
  end
data/tropical.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/ValterAndrei/tropical"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
15
 
16
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+ # spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/ValterAndrei/tropical"
19
19
  spec.metadata["changelog_uri"] = "https://github.com/ValterAndrei/tropical"
@@ -27,8 +27,7 @@ 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
- # spec.add_dependency "example-gem", "~> 1.0"
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
34
33
  # 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
4
+ version: 0.1.9
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-16 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
@@ -17,6 +31,7 @@ executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - ".github/workflows/ci.yml"
20
35
  - ".gitignore"
21
36
  - ".rspec"
22
37
  - ".rubocop.yml"
@@ -34,7 +49,6 @@ files:
34
49
  homepage: https://github.com/ValterAndrei/tropical
35
50
  licenses: []
36
51
  metadata:
37
- allowed_push_host: https://rubygems.org
38
52
  homepage_uri: https://github.com/ValterAndrei/tropical
39
53
  source_code_uri: https://github.com/ValterAndrei/tropical
40
54
  changelog_uri: https://github.com/ValterAndrei/tropical
@@ -53,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  requirements: []
56
- rubygems_version: 3.2.9
70
+ rubygems_version: 3.0.3
57
71
  signing_key:
58
72
  specification_version: 4
59
73
  summary: Weather forecast query