meteo 1.0.2 → 1.1.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 +8 -8
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/meteo.iml +199 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +802 -0
- data/CHANGES +5 -1
- data/bin/meteo +7 -1
- data/lib/meteo/colors.rb +55 -0
- data/lib/meteo/geo.rb +20 -0
- data/lib/meteo/meteo.rb +10 -5
- data/lib/meteo/meteo_cli.rb +13 -11
- data/lib/meteo/version.rb +1 -1
- data/lib/meteo/weather_reporter.rb +147 -0
- data/meteo.gemspec +26 -0
- data/spec/geo_spec.rb +15 -0
- data/spec/meteo_spec.rb +2 -6
- data/spec/spec_helper.rb +2 -0
- data/spec/weather_reporter_spec.rb +11 -0
- metadata +19 -3
- data/lib/meteo/reporter.rb +0 -118
data/lib/meteo/reporter.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module Reporter
|
4
|
-
def report(response, units)
|
5
|
-
sunrise = response['sys']['sunrise']
|
6
|
-
sunset = response['sys']['sunset']
|
7
|
-
|
8
|
-
pressure = response['main']['pressure']
|
9
|
-
|
10
|
-
city = response['name']
|
11
|
-
temperature = response['main']['temp']
|
12
|
-
humidity = response['main']['humidity']
|
13
|
-
|
14
|
-
sky = response['weather'][0]['main']
|
15
|
-
wind = response['wind']['speed']
|
16
|
-
|
17
|
-
current_time = Time.now.to_i
|
18
|
-
|
19
|
-
if current_time >= sunset or current_time <= sunrise
|
20
|
-
period = 'night'
|
21
|
-
else
|
22
|
-
period = 'day'
|
23
|
-
end
|
24
|
-
|
25
|
-
case units
|
26
|
-
when 'metric'
|
27
|
-
scale = "°C"
|
28
|
-
speed_unit = "m/s"
|
29
|
-
pressure_unit = "hPa"
|
30
|
-
pressure = sprintf('%.0f', pressure)
|
31
|
-
when 'imperial'
|
32
|
-
scale = "°F"
|
33
|
-
speed_unit = "mph"
|
34
|
-
pressure_unit = "inHg"
|
35
|
-
pressure = sprintf('%.2f', pressure*0.0295)
|
36
|
-
else
|
37
|
-
# type code here
|
38
|
-
end
|
39
|
-
|
40
|
-
icon = self.send(weather(sky, period))
|
41
|
-
|
42
|
-
background = "\033[44m"
|
43
|
-
dashes = "\033[34m-"
|
44
|
-
text = "\033[36;1m"
|
45
|
-
delimiter = "\033[35m=>"
|
46
|
-
data = "\033[33;1m"
|
47
|
-
stop = "\033[0m"
|
48
|
-
|
49
|
-
%W(
|
50
|
-
#{background}#{text}#{icon}
|
51
|
-
#{city} #{delimiter}#{data}
|
52
|
-
#{text}Temperature #{data}#{temperature}#{scale}
|
53
|
-
#{text}Humidity #{data}#{humidity}%
|
54
|
-
#{text}Wind #{data}#{wind}#{speed_unit}
|
55
|
-
#{text}Pressure #{data}#{pressure}#{pressure_unit}
|
56
|
-
#{text}Sunrise #{data}#{Time.at(sunrise).strftime('%I:%M:%S%p')}
|
57
|
-
#{text}Sunset #{data}#{Time.at(sunset).strftime('%I:%M:%S%p')}#{stop}
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
def weather sky, period
|
62
|
-
case sky
|
63
|
-
when 'Clear'
|
64
|
-
(period == "night") ? 'moon' : 'sun'
|
65
|
-
|
66
|
-
when 'Clouds'
|
67
|
-
"clouds"
|
68
|
-
|
69
|
-
when 'Rain'
|
70
|
-
"rain"
|
71
|
-
|
72
|
-
when 'Fog'
|
73
|
-
"fog"
|
74
|
-
|
75
|
-
when 'Snow'
|
76
|
-
"snow"
|
77
|
-
|
78
|
-
when 'Thunderstorm'
|
79
|
-
"thunderstorm"
|
80
|
-
|
81
|
-
else
|
82
|
-
(period == "night") ? 'moon' : 'sun'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
#def colorize(text, color_code)
|
87
|
-
# "\e[#{color_code}#{text}\e[0m"
|
88
|
-
#end
|
89
|
-
|
90
|
-
def sun
|
91
|
-
"\033[33;1m\xe2\x98\x80"
|
92
|
-
end
|
93
|
-
|
94
|
-
def moon
|
95
|
-
"\033[36m\xe2\x98\xbd"
|
96
|
-
end
|
97
|
-
|
98
|
-
def clouds
|
99
|
-
"\033[37;1m\xe2\x98\x81"
|
100
|
-
end
|
101
|
-
|
102
|
-
def rain
|
103
|
-
"\xe2\x98\x94"
|
104
|
-
end
|
105
|
-
|
106
|
-
def fog
|
107
|
-
"\033[37;1m\xe2\x96\x92"
|
108
|
-
end
|
109
|
-
|
110
|
-
def snow
|
111
|
-
"\033[37;1m\xe2\x9d\x84"
|
112
|
-
end
|
113
|
-
|
114
|
-
def thunderstorm
|
115
|
-
"\xe2\x9a\xa1"
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|