watwa 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/watwa +3 -0
- data/lib/watwa.rb +6 -0
- data/lib/watwa/main.rb +89 -0
- data/tests/test_watwa.rb +10 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cedde112ac44672c7599bff4c681a97ceb5c39a8
|
4
|
+
data.tar.gz: 4ab8b99d3e60cb2b8ffc9e41725d4e5fb494cb14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 936f2143da669597c7a2906450b533d771d204d77702ba1e256b92cef2dfabbc70c185a7977c32e71aa34c2e9be5a53f556e9a59a35c84f45803db678d68a3e9
|
7
|
+
data.tar.gz: 3c91a0069d9304b48ff6d5d906290c11d752985a5df805bd10b42e5b9b2ed17a36128f0ea1c7b08187d0389641fc9edfdc4602c35d947b2a1e9d58552efdf3fd
|
data/bin/watwa
ADDED
data/lib/watwa.rb
ADDED
data/lib/watwa/main.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Displays a 10 day temperature forecast for Melbourne
|
2
|
+
module Watwa
|
3
|
+
require 'tty'
|
4
|
+
require 'weather-api'
|
5
|
+
|
6
|
+
UTF_8 = Encoding::UTF_8
|
7
|
+
C = Weather::Units::CELSIUS
|
8
|
+
|
9
|
+
# Builds a table containing the forecast
|
10
|
+
class Table
|
11
|
+
def initialize
|
12
|
+
@table = TTY::Table.new header: ['Day',
|
13
|
+
'Temp ' + 176.chr(UTF_8) + 'C',
|
14
|
+
'Temp ' + 176.chr(UTF_8) + 'F']
|
15
|
+
@set_colour = SetColour.new
|
16
|
+
@forecast = Forecast.new.response.forecasts
|
17
|
+
end
|
18
|
+
|
19
|
+
# Runs app
|
20
|
+
def run
|
21
|
+
build_table
|
22
|
+
show_table
|
23
|
+
end
|
24
|
+
|
25
|
+
# Pushes each day's weather data into a table
|
26
|
+
def build_table
|
27
|
+
@forecast.each do |item|
|
28
|
+
high = item.high
|
29
|
+
@table << [item.day + ' ' + item.date.day.to_s,
|
30
|
+
@set_colour.colour_c(high),
|
31
|
+
@set_colour.colour_f(convert_to_fahrenheit(high).round)]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Prints the table to the terminal
|
36
|
+
def show_table
|
37
|
+
system 'clear'
|
38
|
+
system 'cls'
|
39
|
+
|
40
|
+
puts 'Melbourne 10 day forecast from Yahoo! weather'
|
41
|
+
puts @table.render(:unicode, padding: [0, 1, 0, 1])
|
42
|
+
end
|
43
|
+
|
44
|
+
# Converts celsius to fahrenheit
|
45
|
+
def convert_to_fahrenheit(temp)
|
46
|
+
temp * 1.8 + 32
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Pulls weather data from Yahoo! Weather API via the weather-api gem
|
51
|
+
class Forecast
|
52
|
+
# Pulls weather forcast from Yahoo Weather
|
53
|
+
attr_accessor :response
|
54
|
+
|
55
|
+
def initialize
|
56
|
+
# Pull weather forcast from Yahoo Weather
|
57
|
+
@response = Weather.lookup_by_location('Melbourne, AU', C)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Uses the pastel gem to set string colours
|
62
|
+
class SetColour
|
63
|
+
def initialize
|
64
|
+
@pastel = Pastel.new
|
65
|
+
end
|
66
|
+
|
67
|
+
# Sets colour for celsius temperature ranges
|
68
|
+
def colour_c(temp)
|
69
|
+
if temp >= 30
|
70
|
+
@pastel.red(temp)
|
71
|
+
elsif temp < 18
|
72
|
+
@pastel.cyan(temp)
|
73
|
+
else
|
74
|
+
@pastel.yellow(temp)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Sets colour for fahrenheit temperature ranges
|
79
|
+
def colour_f(temp)
|
80
|
+
if temp >= 86
|
81
|
+
@pastel.red(temp)
|
82
|
+
elsif temp < 68
|
83
|
+
@pastel.cyan(temp)
|
84
|
+
else
|
85
|
+
@pastel.yellow(temp)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/tests/test_watwa.rb
ADDED
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watwa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
Displays in the terminal a table of the next 10 days
|
15
|
+
maximum temperature forecast for Melbourne, AU
|
16
|
+
email:
|
17
|
+
- chrisxrobertson@gmail.com
|
18
|
+
executables:
|
19
|
+
- watwa
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- bin/watwa
|
24
|
+
- lib/watwa.rb
|
25
|
+
- lib/watwa/main.rb
|
26
|
+
- tests/test_watwa.rb
|
27
|
+
homepage: http://domainforproject.com/
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.6.8
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: WATWA, A Termainl Weather App
|
51
|
+
test_files:
|
52
|
+
- tests/test_watwa.rb
|