tropical 0.1.5 → 0.2.0

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: 773b86e10df59f914fc84c955a6c9098f51cce682b027eb8b3052e4f7f622d2e
4
- data.tar.gz: 7dd04dfbcaa8bf919f40edb1f4a8be500d4c18b40a4c293dd6cc87675677c118
3
+ metadata.gz: 05a134ba1ecc9bfd663073a79e370fb1fc8051464fe14c3be7627b7d9e0d9548
4
+ data.tar.gz: 742fd0b18c6c12006ebcea83b6c86c3a974b8c250b2f7e697bebf83d2b5694b0
5
5
  SHA512:
6
- metadata.gz: 99efe601b047c5bc204d9a70c403e23a559f1a321e3f55531d32c82daefa1981e498a54625056cdc0be93729708e47805e2e4672913e54df4affa0abb54372d5
7
- data.tar.gz: bff9a8af48ec17d96be5f7b6b3749de6681acc227a1ac058bcb2f4221e2b3205bb2009499d0c7e904a4e520c1ad2feedc182985233aed38c22241cade4f8fea5
6
+ metadata.gz: d818c360ae912aab451d70c0b5131457192996b0ccd706a164f7220b8a8895f2397d8dd6788b98f229fa4b9e7236cfe2f85451291d5cc4e9eb21a4e0ef05995a
7
+ data.tar.gz: eea2d0b6a9453f8cc34533681c533be4b704168eac3d3a7bca37f3fd5897f846903066f0972902a4e5a537b9d47279d2a7b13bac037e20f7f6464ea958e8bcbe
@@ -0,0 +1,52 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths-ignore:
8
+ - README.md
9
+
10
+ jobs:
11
+ build:
12
+ name: Build + Publish
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby 2.6
18
+ uses: actions/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.6.x
21
+
22
+ - name: Run the default task
23
+ run: |
24
+ gem install bundler -v 2.2.9
25
+ bundle install
26
+ bundle exec rake
27
+
28
+ - name: Test
29
+ run: bundle exec rspec
30
+
31
+ - name: Publish to GPR
32
+ run: |
33
+ mkdir -p $HOME/.gem
34
+ touch $HOME/.gem/credentials
35
+ chmod 0600 $HOME/.gem/credentials
36
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
37
+ gem build *.gemspec
38
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
39
+ env:
40
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
41
+ OWNER: ${{ github.repository_owner }}
42
+
43
+ - name: Publish to RubyGems
44
+ run: |
45
+ mkdir -p $HOME/.gem
46
+ touch $HOME/.gem/credentials
47
+ chmod 0600 $HOME/.gem/credentials
48
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
49
+ gem build *.gemspec
50
+ gem push *.gem
51
+ env:
52
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.rubocop.yml CHANGED
@@ -11,3 +11,12 @@ Style/StringLiteralsInInterpolation:
11
11
 
12
12
  Layout/LineLength:
13
13
  Max: 120
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: false
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: false
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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tropical (0.1.5)
4
+ tropical (0.2.0)
5
5
  activesupport (~> 6.1.2.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,18 +1,15 @@
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.
3
+ ![Ruby Gem](https://github.com/ValterAndrei/tropical/workflows/Ruby%20Gem/badge.svg)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Gem to search weather forecast for 5 days:
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'tropical'
13
-
14
- # or
15
- gem 'tropical', git: 'https://github.com/valterandrei/tropical', branch: 'main'
12
+ gem 'tropical', '~> 0.2.0'
16
13
  ```
17
14
 
18
15
  And then execute:
@@ -21,7 +18,98 @@ And then execute:
21
18
 
22
19
  ## Usage
23
20
 
24
- TODO: Write usage instructions here
21
+ Ruby API
22
+ ```ruby
23
+ tropical = Tropical::OpenWeatherMap.new(
24
+ {
25
+ appid: 'your_api_key', # required
26
+ q: 'São Paulo', # required
27
+ lang: 'pt_br', # optional
28
+ units: 'metric', # optional
29
+ cnt: '50' # optional
30
+ }
31
+ )
32
+ ```
33
+ For more information about the params: [openweathermap](https://openweathermap.org/forecast5)
34
+
35
+ Note: The `mode` param is not avaible.
36
+
37
+ - City name
38
+ ```ruby
39
+ tropical.city_name
40
+
41
+ # => "São Paulo"
42
+ ```
43
+
44
+ - Population
45
+ ```ruby
46
+ tropical.population
47
+
48
+ # => 10021295
49
+ ```
50
+
51
+ - Country
52
+ ```ruby
53
+ tropical.country
54
+
55
+ # => "BR"
56
+ ```
57
+
58
+ - Current date
59
+ ```ruby
60
+ tropical.current_date
61
+
62
+ # => 2021-02-14 18:00:00 -0300
63
+ ```
64
+
65
+ - Coord
66
+ ```ruby
67
+ tropical.coord
68
+
69
+ # => {:lat=>-23.5475, :lon=>-46.6361}
70
+ ```
71
+
72
+ - Scale
73
+ ```ruby
74
+ tropical.scale
75
+
76
+ # => "°C"
77
+ ```
78
+
79
+ - Current temperature
80
+ ```ruby
81
+ tropical.current_temp
82
+
83
+ # => 26.92
84
+ ```
85
+
86
+ - Current weather
87
+ ```ruby
88
+ tropical.current_weather
89
+
90
+ # => "chuva moderada"
91
+ ```
92
+
93
+ - Full sumary
94
+ ```ruby
95
+ tropical.full_sumary
96
+
97
+ # => "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."
98
+ ```
99
+
100
+ - Sumary current day
101
+ ```ruby
102
+ tropical.sumary_current_day
103
+
104
+ # => "27°C e chuva moderada em São Paulo em 14/02."
105
+ ```
106
+
107
+ - Sumary days forecast
108
+ ```ruby
109
+ tropical.sumary_days_forecast
110
+
111
+ # => "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."
112
+ ```
25
113
 
26
114
  ## Development
27
115
 
@@ -31,8 +119,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
31
119
 
32
120
  ## Contributing
33
121
 
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).
122
+ 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
123
 
36
124
  ## Code of Conduct
37
125
 
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).
126
+ 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,6 +1,7 @@
1
1
  require "active_support/all"
2
2
  require "date"
3
3
  require "json"
4
+ require "i18n"
4
5
  require "net/http"
5
6
  require "uri"
6
7
 
@@ -17,25 +18,24 @@ module Tropical
17
18
  load_data(response)
18
19
  end
19
20
 
20
- def average_temp_by_days
21
- group_by_days = list.group_by { |item| item[:datetime].to_date }
22
- days = []
23
-
24
- group_by_days.each do |day, temps|
25
- average = temps.sum { |time| time[:temp] } / temps.length
21
+ def city_name
22
+ data["city"]["name"]
23
+ end
26
24
 
27
- days << { day: day, average: average.round }
28
- end
25
+ def country
26
+ data["city"]["country"]
27
+ end
29
28
 
30
- days
29
+ def population
30
+ data["city"]["population"]
31
31
  end
32
32
 
33
- def city
34
- data["city"]["name"]
33
+ def coord
34
+ data["city"]["coord"].transform_keys(&:to_sym)
35
35
  end
36
36
 
37
37
  def current_date
38
- list.first[:datetime]
38
+ list.first[:dt]
39
39
  end
40
40
 
41
41
  def current_temp
@@ -46,16 +46,6 @@ module Tropical
46
46
  list.first[:description]
47
47
  end
48
48
 
49
- def list
50
- data["list"].map do |list_item|
51
- {
52
- datetime: Time.at(list_item["dt"]),
53
- temp: list_item["main"]["temp"],
54
- description: list_item["weather"].first["description"]
55
- }
56
- end
57
- end
58
-
59
49
  def scale
60
50
  units = params[:units]
61
51
 
@@ -65,16 +55,23 @@ module Tropical
65
55
  "°K"
66
56
  end
67
57
 
68
- def sumary
69
- message = format_message
70
-
71
- "#{message.current_temp}#{scale} e #{current_weather} em #{city} em #{message.current_date}. "\
58
+ def full_sumary
59
+ "#{sumary_current_day} "\
72
60
  "Média para os próximos dias: "\
73
- "#{message.first_day_average}#{scale} em #{message.first_day_date}, "\
74
- "#{message.second_day_average}#{scale} em #{message.second_day_date}, "\
75
- "#{message.third_day_average}#{scale} em #{message.third_day_date}, "\
76
- "#{message.fourth_day_average}#{scale} em #{message.fourth_day_date} "\
77
- "e #{message.fifth_day_average}#{scale} em #{message.fifth_day_date}."
61
+ "#{sumary_days_forecast}"
62
+ end
63
+
64
+ def sumary_current_day
65
+ "#{current_temp.round}#{scale} e #{current_weather} em "\
66
+ "#{city_name} em #{current_date.strftime("%d/%m")}."
67
+ end
68
+
69
+ def sumary_days_forecast
70
+ list = average_temp_by_days.map do |x|
71
+ "#{x[:average]}#{scale} em #{x[:day].strftime("%d/%m")}"
72
+ end
73
+
74
+ "#{list.to_sentence(words_connector: ", ", last_word_connector: " e ")}."
78
75
  end
79
76
 
80
77
  private
@@ -83,29 +80,15 @@ module Tropical
83
80
  link = ""
84
81
 
85
82
  params.each do |k, v|
86
- link += "&#{k}=#{v}" if v.is_a?(String) && v.present?
83
+ next if k == :mode
84
+ next unless v.is_a?(String) && v.present?
85
+
86
+ link += "&#{k}=#{I18n.transliterate(v)}"
87
87
  end
88
88
 
89
89
  BASE_URL + link
90
90
  end
91
91
 
92
- def format_message
93
- OpenStruct.new(
94
- current_temp: current_temp.round,
95
- current_date: current_date.strftime("%d/%m"),
96
- first_day_average: average_temp_by_days[0][:average],
97
- first_day_date: average_temp_by_days[0][:day].strftime("%d/%m"),
98
- second_day_average: average_temp_by_days[1][:average],
99
- second_day_date: average_temp_by_days[1][:day].strftime("%d/%m"),
100
- third_day_average: average_temp_by_days[2][:average],
101
- third_day_date: average_temp_by_days[2][:day].strftime("%d/%m"),
102
- fourth_day_average: average_temp_by_days[3][:average],
103
- fourth_day_date: average_temp_by_days[3][:day].strftime("%d/%m"),
104
- fifth_day_average: average_temp_by_days[4][:average],
105
- fifth_day_date: average_temp_by_days[4][:day].strftime("%d/%m")
106
- )
107
- end
108
-
109
92
  def load_data(response)
110
93
  @status = response.code
111
94
  @data = case response
@@ -118,6 +101,29 @@ module Tropical
118
101
  end
119
102
  end
120
103
 
104
+ def average_temp_by_days
105
+ group_by_days = list.group_by { |item| item[:dt].to_date }
106
+ days = []
107
+
108
+ group_by_days.each do |day, temps|
109
+ average = temps.sum { |time| time[:temp] } / temps.length
110
+
111
+ days << { day: day, average: average.round }
112
+ end
113
+
114
+ days
115
+ end
116
+
117
+ def list
118
+ data["list"].map do |list_item|
119
+ {
120
+ dt: Time.at(list_item["dt"]).utc,
121
+ temp: list_item["main"]["temp"],
122
+ description: list_item["weather"].first["description"]
123
+ }
124
+ end
125
+ end
126
+
121
127
  def post(request_params)
122
128
  url = URI(request_params)
123
129
  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.5"
4
+ VERSION = "0.2.0"
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,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.5
4
+ version: 0.2.0
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
11
+ date: 2021-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/workflows/ci.yml"
34
35
  - ".gitignore"
35
36
  - ".rspec"
36
37
  - ".rubocop.yml"
@@ -48,7 +49,6 @@ files:
48
49
  homepage: https://github.com/ValterAndrei/tropical
49
50
  licenses: []
50
51
  metadata:
51
- allowed_push_host: https://rubygems.org
52
52
  homepage_uri: https://github.com/ValterAndrei/tropical
53
53
  source_code_uri: https://github.com/ValterAndrei/tropical
54
54
  changelog_uri: https://github.com/ValterAndrei/tropical
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.2.9
70
+ rubygems_version: 3.0.3
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Weather forecast query