weather_by_dcq 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 347e358c47d447a931e591422bf1758fdf4a08f6744dc487c830847e7653a6d9
4
+ data.tar.gz: e367d72ed6db35e351a52b2b4c25d96c14a87b10c23842eea0453603bd677fc7
5
+ SHA512:
6
+ metadata.gz: 75c438ecb52b4fc4ef357daf9ffad802d3fe0230e17f22a8e05d22f576350c5c73de2616df0e19f9392629fb7f7c7fc91f258afa553931df4b6c68273b747804
7
+ data.tar.gz: f9f6f75b5bd51d93d979531e321d1ee8f487072570827efeddc73534ec95188cb78263c93ab9408c51fcda4a2862dc53afee5b58fb637d88592a00e7d30cebdd
@@ -0,0 +1,279 @@
1
+ # Created by https://www.gitignore.io/api/windows,macos,linux,visualstudiocode,jetbrains+all,ruby,rubymine+all
2
+ # Edit at https://www.gitignore.io/?templates=windows,macos,linux,visualstudiocode,jetbrains+all,ruby,rubymine+all
3
+
4
+ ### JetBrains+all ###
5
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
6
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7
+
8
+ # User-specific stuff
9
+ .idea/**/workspace.xml
10
+ .idea/**/tasks.xml
11
+ .idea/**/usage.statistics.xml
12
+ .idea/**/dictionaries
13
+ .idea/**/shelf
14
+
15
+ # Generated files
16
+ .idea/**/contentModel.xml
17
+
18
+ # Sensitive or high-churn files
19
+ .idea/**/dataSources/
20
+ .idea/**/dataSources.ids
21
+ .idea/**/dataSources.local.xml
22
+ .idea/**/sqlDataSources.xml
23
+ .idea/**/dynamic.xml
24
+ .idea/**/uiDesigner.xml
25
+ .idea/**/dbnavigator.xml
26
+
27
+ # Gradle
28
+ .idea/**/gradle.xml
29
+ .idea/**/libraries
30
+
31
+ # Gradle and Maven with auto-import
32
+ # When using Gradle or Maven with auto-import, you should exclude module files,
33
+ # since they will be recreated, and may cause churn. Uncomment if using
34
+ # auto-import.
35
+ # .idea/modules.xml
36
+ # .idea/*.iml
37
+ # .idea/modules
38
+ # *.iml
39
+ # *.ipr
40
+
41
+ # CMake
42
+ cmake-build-*/
43
+
44
+ # Mongo Explorer plugin
45
+ .idea/**/mongoSettings.xml
46
+
47
+ # File-based project format
48
+ *.iws
49
+
50
+ # IntelliJ
51
+ out/
52
+
53
+ # mpeltonen/sbt-idea plugin
54
+ .idea_modules/
55
+
56
+ # JIRA plugin
57
+ atlassian-ide-plugin.xml
58
+
59
+ # Cursive Clojure plugin
60
+ .idea/replstate.xml
61
+
62
+ # Crashlytics plugin (for Android Studio and IntelliJ)
63
+ com_crashlytics_export_strings.xml
64
+ crashlytics.properties
65
+ crashlytics-build.properties
66
+ fabric.properties
67
+
68
+ # Editor-based Rest Client
69
+ .idea/httpRequests
70
+
71
+ # Android studio 3.1+ serialized cache file
72
+ .idea/caches/build_file_checksums.ser
73
+
74
+ ### JetBrains+all Patch ###
75
+ # Ignores the whole .idea folder and all .iml files
76
+ # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
77
+
78
+ .idea/
79
+
80
+ # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
81
+
82
+ *.iml
83
+ modules.xml
84
+ .idea/misc.xml
85
+ *.ipr
86
+
87
+ # Sonarlint plugin
88
+ .idea/sonarlint
89
+
90
+ ### Linux ###
91
+ *~
92
+
93
+ # temporary files which can be created if a process still has a handle open of a deleted file
94
+ .fuse_hidden*
95
+
96
+ # KDE directory preferences
97
+ .directory
98
+
99
+ # Linux trash folder which might appear on any partition or disk
100
+ .Trash-*
101
+
102
+ # .nfs files are created when an open file is removed but is still being accessed
103
+ .nfs*
104
+
105
+ ### macOS ###
106
+ # General
107
+ .DS_Store
108
+ .AppleDouble
109
+ .LSOverride
110
+
111
+ # Icon must end with two \r
112
+ Icon
113
+
114
+ # Thumbnails
115
+ ._*
116
+
117
+ # Files that might appear in the root of a volume
118
+ .DocumentRevisions-V100
119
+ .fseventsd
120
+ .Spotlight-V100
121
+ .TemporaryItems
122
+ .Trashes
123
+ .VolumeIcon.icns
124
+ .com.apple.timemachine.donotpresent
125
+
126
+ # Directories potentially created on remote AFP share
127
+ .AppleDB
128
+ .AppleDesktop
129
+ Network Trash Folder
130
+ Temporary Items
131
+ .apdisk
132
+
133
+ ### Ruby ###
134
+ *.gem
135
+ *.rbc
136
+ .rspec_status
137
+ /.config
138
+ /coverage/
139
+ /InstalledFiles
140
+ /pkg/
141
+ /spec/reports/
142
+ /spec/examples.txt
143
+ /test/tmp/
144
+ /test/version_tmp/
145
+ /tmp/
146
+
147
+ # Used by dotenv library to load environment variables.
148
+ # .env
149
+
150
+ # Ignore Byebug command history file.
151
+ .byebug_history
152
+
153
+ ## Specific to RubyMotion:
154
+ .dat*
155
+ .repl_history
156
+ build/
157
+ *.bridgesupport
158
+ build-iPhoneOS/
159
+ build-iPhoneSimulator/
160
+
161
+ ## Specific to RubyMotion (use of CocoaPods):
162
+ #
163
+ # We recommend against adding the Pods directory to your .gitignore. However
164
+ # you should judge for yourself, the pros and cons are mentioned at:
165
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
166
+ # vendor/Pods/
167
+
168
+ ## Documentation cache and generated files:
169
+ /.yardoc/
170
+ /_yardoc/
171
+ /doc/
172
+ /rdoc/
173
+
174
+ ## Environment normalization:
175
+ /.bundle/
176
+ /vendor/bundle
177
+ /lib/bundler/man/
178
+
179
+ # for a library or gem, you might want to ignore these files since the code is
180
+ # intended to run in multiple environments; otherwise, check them in:
181
+ # Gemfile.lock
182
+ # .ruby-version
183
+ # .ruby-gemset
184
+
185
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
186
+ .rvmrc
187
+
188
+ ### RubyMine+all ###
189
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
190
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
191
+
192
+ # User-specific stuff
193
+
194
+ # Generated files
195
+
196
+ # Sensitive or high-churn files
197
+
198
+ # Gradle
199
+
200
+ # Gradle and Maven with auto-import
201
+ # When using Gradle or Maven with auto-import, you should exclude module files,
202
+ # since they will be recreated, and may cause churn. Uncomment if using
203
+ # auto-import.
204
+ # .idea/modules.xml
205
+ # .idea/*.iml
206
+ # .idea/modules
207
+ # *.iml
208
+ # *.ipr
209
+
210
+ # CMake
211
+
212
+ # Mongo Explorer plugin
213
+
214
+ # File-based project format
215
+
216
+ # IntelliJ
217
+
218
+ # mpeltonen/sbt-idea plugin
219
+
220
+ # JIRA plugin
221
+
222
+ # Cursive Clojure plugin
223
+
224
+ # Crashlytics plugin (for Android Studio and IntelliJ)
225
+
226
+ # Editor-based Rest Client
227
+
228
+ # Android studio 3.1+ serialized cache file
229
+
230
+ ### RubyMine+all Patch ###
231
+ # Ignores the whole .idea folder and all .iml files
232
+ # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
233
+
234
+
235
+ # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
236
+
237
+
238
+ # Sonarlint plugin
239
+
240
+ ### VisualStudioCode ###
241
+ .vscode/*
242
+ !.vscode/settings.json
243
+ !.vscode/tasks.json
244
+ !.vscode/launch.json
245
+ !.vscode/extensions.json
246
+
247
+ ### VisualStudioCode Patch ###
248
+ # Ignore all local history of files
249
+ .history
250
+
251
+ ### Windows ###
252
+ # Windows thumbnail cache files
253
+ Thumbs.db
254
+ Thumbs.db:encryptable
255
+ ehthumbs.db
256
+ ehthumbs_vista.db
257
+
258
+ # Dump file
259
+ *.stackdump
260
+
261
+ # Folder config file
262
+ [Dd]esktop.ini
263
+
264
+ # Recycle Bin used on file shares
265
+ $RECYCLE.BIN/
266
+
267
+ # Windows Installer files
268
+ *.cab
269
+ *.msi
270
+ *.msix
271
+ *.msm
272
+ *.msp
273
+
274
+ # Windows shortcuts
275
+ *.lnk
276
+
277
+ # End of https://www.gitignore.io/api/windows,macos,linux,visualstudiocode,jetbrains+all,ruby,rubymine+all
278
+
279
+ .env
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at YOUR@EMAIL.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in weather_by_dcq.gemspec
6
+ gemspec
7
+
8
+ gem 'forecast_io'
9
+ gem 'geocoder'
10
+ gem 'httparty'
11
+ gem 'json'
12
+ gem 'pry'
13
+ gem 'rake'
14
+ gem 'tty-spinner'
15
+ gem 'tty-table'
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ weather_by_dcq (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ colorize (0.8.1)
11
+ diff-lcs (1.3)
12
+ equatable (0.6.1)
13
+ faraday (0.17.1)
14
+ multipart-post (>= 1.2, < 3)
15
+ forecast_io (2.0.2)
16
+ faraday
17
+ hashie
18
+ multi_json
19
+ geocoder (1.5.2)
20
+ hashie (4.0.0)
21
+ httparty (0.17.3)
22
+ mime-types (~> 3.0)
23
+ multi_xml (>= 0.5.2)
24
+ json (2.3.0)
25
+ method_source (0.9.2)
26
+ mime-types (3.3)
27
+ mime-types-data (~> 3.2015)
28
+ mime-types-data (3.2019.1009)
29
+ multi_json (1.14.1)
30
+ multi_xml (0.6.0)
31
+ multipart-post (2.1.1)
32
+ necromancer (0.5.1)
33
+ pastel (0.7.3)
34
+ equatable (~> 0.6)
35
+ tty-color (~> 0.5)
36
+ pry (0.12.2)
37
+ coderay (~> 1.1.0)
38
+ method_source (~> 0.9.0)
39
+ rake (13.0.1)
40
+ rspec (3.9.0)
41
+ rspec-core (~> 3.9.0)
42
+ rspec-expectations (~> 3.9.0)
43
+ rspec-mocks (~> 3.9.0)
44
+ rspec-core (3.9.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-expectations (3.9.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-mocks (3.9.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-support (3.9.0)
53
+ strings (0.1.8)
54
+ strings-ansi (~> 0.1)
55
+ unicode-display_width (~> 1.5)
56
+ unicode_utils (~> 1.4)
57
+ strings-ansi (0.2.0)
58
+ tty-color (0.5.0)
59
+ tty-cursor (0.7.0)
60
+ tty-screen (0.7.0)
61
+ tty-spinner (0.9.2)
62
+ tty-cursor (~> 0.7)
63
+ tty-table (0.11.0)
64
+ equatable (~> 0.6)
65
+ necromancer (~> 0.5)
66
+ pastel (~> 0.7.2)
67
+ strings (~> 0.1.5)
68
+ tty-screen (~> 0.7)
69
+ unicode-display_width (1.6.0)
70
+ unicode_utils (1.4.0)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (~> 2.1.0)
77
+ colorize (~> 0.8.1)
78
+ forecast_io
79
+ geocoder
80
+ httparty
81
+ json
82
+ pry
83
+ rake
84
+ rspec (~> 3.9.0)
85
+ tty-spinner
86
+ tty-table
87
+ weather_by_dcq!
88
+
89
+ BUNDLED WITH
90
+ 2.1.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 YOUR NAME
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # WeatherByDcq
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/weather_by_dcq`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ Get DarkSky API
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'weather_by_dcq'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install weather_by_dcq
22
+
23
+ ## Usage
24
+
25
+ WeatherByDcq::View.new.menu
26
+ <img src="https://i.imgur.com/d2eswbf.jpg" />
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/TOMOSIA-VIETNAM/weather_by_dcq. 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/TOMOSIA-VIETNAM/weather_by_dcq/blob/master/CODE_OF_CONDUCT.md).
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the WeatherByDcq project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/TOMOSIA-VIETNAM/weather_by_dcq/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'weather_by_dcq'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'weather_ferret'
5
+
6
+ WeatherFerret::CLI.new.call
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/weather_by_dcq/version'
4
+ require_relative '../lib/weather_by_dcq/request'
5
+ require_relative '../lib/weather_by_dcq/forecast'
6
+ require_relative '../lib/weather_by_dcq/view'
7
+
8
+
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty-spinner'
4
+ require 'tty-table'
5
+ require 'pry'
6
+
7
+ class WeatherByDcq::Forecast
8
+ def self.fetch_curr_data(key_data)
9
+ @forecast['currently'][key_data]
10
+ end
11
+
12
+ def self.fetch_data(num, key_data)
13
+ @forecast['daily']['data'][num][key_data]
14
+ end
15
+
16
+ def self.fetch_sun_data(num, key_data)
17
+ time = Time.at(@forecast['daily']['data'][num][key_data])
18
+ time.strftime('%I:%M ')
19
+ end
20
+
21
+ def self.display_curr_table(location)
22
+ ## Add TTY Spinner
23
+ spinner = TTY::Spinner.new('[:spinner] Fetch from API', format: :bouncing_ball, clear: true)
24
+ 30.times do
25
+ spinner.spin
26
+ sleep(0.1)
27
+ end
28
+ spinner.success
29
+
30
+ @forecast = WeatherByDcq::Request.fetch(location)
31
+ puts ''
32
+ puts '🌐 ' + @forecast['timezone']
33
+
34
+ temperature = fetch_curr_data('temperature').to_i
35
+ @temperature = ((temperature - 32) / 1.8).round(2)
36
+ apparentTemperature = fetch_curr_data('apparentTemperature').to_i
37
+ @apparentTemperature = ((apparentTemperature - 32) / 1.8).round(2)
38
+
39
+ curr_table = TTY::Table.new ["\u{1F321} Temp.: #{@temperature}°C",
40
+ "\u{1F321} Heat Index: #{@apparentTemperature}°C"],
41
+ [["\u{1F4A6} Humidity: #{fetch_curr_data('humidity')}\u{0025}",
42
+ "🌀 Wind Speed: #{fetch_curr_data('windSpeed')}mph"]]
43
+ puts curr_table.render(:ascii, padding: [0, 2])
44
+ puts ''
45
+ end
46
+
47
+ def self.display_forecast_list
48
+ @forecast['daily'].each do |key, value|
49
+ next unless key == 'data'
50
+
51
+ value.each.with_index do |n, index|
52
+ date = Time.at(n['time'])
53
+ puts "#{index + 1})".colorize(:blue) + " #{date.strftime('%a')} - #{date.month}/#{date.day}"
54
+ end
55
+ end
56
+ end
57
+
58
+ def self.display_details(num)
59
+ puts ''
60
+ display_forecast_list
61
+ puts ''
62
+
63
+ num -= 1
64
+ date = Time.at(@forecast['daily']['data'][num]['time'])
65
+ puts ''
66
+ puts " Detailed forecast on #{date.strftime('%a')} - #{date.month}/#{date.day}".colorize(:blue)
67
+ puts ' ========================================================================='.colorize(:blue)
68
+
69
+ hi = fetch_data(num, 'temperatureHigh').to_i
70
+ @hi = ((hi - 32) / 1.8).round(2)
71
+ lo = fetch_data(num, 'temperatureLow').to_i
72
+ @lo = ((lo - 32) / 1.8).round(2)
73
+ hea = fetch_data(num, 'apparentTemperatureHigh').to_i
74
+ @hea = ((hea - 32) / 1.8).round(2)
75
+
76
+ # Build table
77
+ detail_table = TTY::Table.new do |t|
78
+ t << ["\u{1F321} High: #{@hi}°C",
79
+ "\u{1F321} Low: #{@lo}°C",
80
+ "\u{1F321} Heat Index: #{@hea}°C"]
81
+ t << ["🌀 Wind: #{fetch_data(num, 'windSpeed').to_i}mph",
82
+ "🌦 Precip Prob.: #{(fetch_data(num, 'precipProbability') * 100).to_i}\u{0025}",
83
+ "🌧 Precip.: #{fetch_data(num, 'precipType').to_s.capitalize}"]
84
+ t << ["💧 Humidity: #{(fetch_data(num, 'humidity') * 100).to_i}\u{0025}",
85
+ "🌇 Sunrise: #{fetch_sun_data(num, 'sunriseTime')}AM", "🌆 Sunset: #{fetch_sun_data(num, 'sunsetTime')}PM"]
86
+ end
87
+
88
+ puts " #{fetch_data(num, 'summary')}".colorize(:red)
89
+ puts ''
90
+ @icon = fetch_data(num, 'icon')
91
+ if @icon.eql? 'rain'
92
+ puts " \u{2614}" + " #{@icon}".colorize(:yellow)
93
+ elsif @icon.eql?'clear-day'
94
+ puts " \u{1F324}" + " #{@icon}".colorize(:yellow)
95
+ elsif @icon.eql?'fog'
96
+ puts " \u{1F32B}" + " #{@icon}".colorize(:yellow)
97
+ else
98
+ puts " \u{1F325}" + " #{@icon}".colorize(:yellow)
99
+ end
100
+
101
+ puts detail_table.render(:ascii, padding: [0, 2]) { |renderer|
102
+ renderer.border.separator = :each_row
103
+ renderer.border.style = :cyan
104
+ }
105
+ end
106
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forecast_io'
4
+ require 'geocoder'
5
+ require 'pry'
6
+
7
+
8
+ # export
9
+
10
+ class WeatherByDcq::Request
11
+ attr_accessor :location
12
+
13
+ def initialize(location)
14
+ @location = location
15
+ end
16
+
17
+ # Convert user entered location to geodetic coordinates
18
+ def self.coordinate_pts(location)
19
+ city = Geocoder.search(location)
20
+ if city[0].nil?
21
+ puts "Not Found"
22
+ return WeatherByDcq::View.new.menu
23
+ else
24
+ @lat = city[0].latitude
25
+ @lon = city[0].longitude
26
+ end
27
+ end
28
+
29
+ # fetch forecast hash from Dark Sky API
30
+ def self.fetch(location)
31
+ coordinate_pts(location)
32
+ ForecastIO.configure do |c|
33
+ c.api_key = '4aac124157c348289553a5e7fdc1899d'
34
+ c.default_params = { time: 600, exclude: 'minutely, hourly' }
35
+ end
36
+ @forecast = ForecastIO.forecast(@lat, @lon)
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherByDcq
4
+ VERSION = '0.1.3'
5
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+ require 'pry'
5
+
6
+ class WeatherByDcq::View
7
+ attr_accessor :location, :forecast
8
+
9
+ def menu
10
+ puts ''
11
+ puts 'Please enter a city to retrieve a forecast (Format: City State):'
12
+ input_location = gets.strip
13
+ location = input_location.gsub(/[\W\d]/, '').downcase
14
+
15
+ puts "You entered: #{location}".colorize(:blue) + ' Is this correct (Y/N)?'
16
+ input_confirm = gets.strip.downcase
17
+ if input_confirm == 'n'
18
+ puts 'I am sorry, let us try again.'
19
+ menu
20
+ elsif input_confirm == 'y'
21
+ system('cls') || system('clear')
22
+ puts ''
23
+ puts "Current Conditions for #{location}:".colorize(:blue)
24
+ puts '====================================='
25
+ WeatherByDcq::Forecast.display_curr_table(location)
26
+
27
+ # Extended forecast List
28
+ puts 'Extended forecast:'.colorize(:blue)
29
+ puts '--------------------'
30
+ WeatherByDcq::Forecast.display_forecast_list
31
+ puts ''
32
+ options_menu
33
+ else
34
+ begin
35
+ raise WeatherError
36
+ rescue WeatherError => e
37
+ puts e.message
38
+ end
39
+ menu
40
+ end
41
+ end
42
+
43
+ def options_menu
44
+ puts ''
45
+ puts 'Would you like additional details about any of the days listed?'.colorize(:blue)
46
+ puts 'Please enter the corresponding number for your request, or any letter to EXIT: '.colorize(:blue)
47
+ detail_input = gets.strip.to_i
48
+ if detail_input.positive? && detail_input < 9
49
+ system('cls') || system('clear')
50
+ WeatherByDcq::Forecast.display_details(detail_input)
51
+ options_menu
52
+
53
+ elsif detail_input.negative? || detail_input > 8
54
+ begin
55
+ raise WeatherError
56
+ rescue WeatherError => e
57
+ puts e.message
58
+ end
59
+ options_menu
60
+ else
61
+ exit
62
+ end
63
+ end
64
+
65
+ class WeatherError < StandardError
66
+ def message
67
+ puts ''
68
+ puts ' <== ERROR ==>'.colorize(:white).on_red
69
+ puts ''
70
+ puts ' I do not understand your response, please try again.'.colorize(:yellow)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require_relative 'lib/weather_by_dcq/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'weather_by_dcq'
9
+ spec.version = WeatherByDcq::VERSION
10
+ spec.authors = ['Doan Trung Quan']
11
+ spec.email = ['doantrungquan97@gmail.com']
12
+
13
+ spec.summary = 'Weather API'
14
+ spec.description = 'DarkSky API'
15
+ spec.homepage = 'https://github.com/TOMOSIA-VIETNAM/weather_by_dcq'
16
+ spec.license = 'MIT'
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/TOMOSIA-VIETNAM/weather_by_dcq.'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/TOMOSIA-VIETNAM/weather_by_dcq.'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.1.0'
33
+ spec.add_development_dependency 'colorize', '~>0.8.1'
34
+ spec.add_development_dependency 'forecast_io', '~>2.0.2'
35
+ spec.add_development_dependency 'geocoder', '~>1.5.2'
36
+ spec.add_development_dependency 'json', '~>2.3.0'
37
+ spec.add_development_dependency 'pry', '~>0.12.2'
38
+ spec.add_development_dependency 'rake', '~> 13.0.1'
39
+ spec.add_development_dependency 'rspec', '~> 3.9.0'
40
+ spec.add_development_dependency 'tty-spinner', '~>0.9.2'
41
+ spec.add_development_dependency 'tty-table', '~>0.11.0'
42
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_by_dcq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Doan Trung Quan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: forecast_io
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: geocoder
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.12.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.12.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 13.0.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 13.0.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.9.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.9.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: tty-spinner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: tty-table
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.11.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.11.0
153
+ description: DarkSky API
154
+ email:
155
+ - doantrungquan97@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - CODE_OF_CONDUCT.md
162
+ - Gemfile
163
+ - Gemfile.lock
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - bin/weather-by-dcq.rb
170
+ - lib/weather_by_dcq.rb
171
+ - lib/weather_by_dcq/forecast.rb
172
+ - lib/weather_by_dcq/request.rb
173
+ - lib/weather_by_dcq/version.rb
174
+ - lib/weather_by_dcq/view.rb
175
+ - weather_by_dcq.gemspec
176
+ homepage: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq
177
+ licenses:
178
+ - MIT
179
+ metadata:
180
+ homepage_uri: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq
181
+ source_code_uri: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq.
182
+ changelog_uri: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq.
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: 2.3.0
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubygems_version: 3.0.1
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Weather API
202
+ test_files: []