meteo 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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