Skip to content

Instantly share code, notes, and snippets.

@rob-murray
Last active October 13, 2015 01:57
Show Gist options
  • Save rob-murray/4120977 to your computer and use it in GitHub Desktop.
Save rob-murray/4120977 to your computer and use it in GitHub Desktop.
Simple class to return the climacon character for the yahoo weather api code
#
# Simple map to return the character required for correct
# climacon based on yahoo weather code.
# https://gist.github.com/rob-murray/4120977
#
# @params {integer} the Yahoo weather code ID
# @returns {string} the Climacon character
#
# @see http://adamwhitcroft.com/climacons/font/,
# https://developer.yahoo.com/weather/documentation.html#codes
#
# Usage: YahooClimaconCode.new(20).to_s
#
class YahooClimaconCode < Struct.new(:yahoo_code)
def to_s
yahoo_code_map.fetch(yahoo_code.to_i, default)
end
private
def default
''
end
def yahoo_code_map
{
0 => '(',
1 => 'k',
2 => 'k',
3 => 'z',
4 => 'z',
5 => 'y',
6 => 'y',
7 => 'y',
8 => 'y',
9 => '9',
10 => '9',
11 => '9',
12 => '9',
13 => 'o',
14 => 'o',
15 => 'o',
16 => 'o',
17 => 'y',
18 => 'e',
19 => 'g',
20 => '20',
21 => '20',
22 => 's',
23 => 'k',
24 => 'k',
25 => ']',
26 => '`',
27 => '2',
28 => '1',
29 => '2',
30 => '1',
31 => '/',
32 => 'v',
33 => '2',
34 => '1',
35 => 'y',
36 => 'E',
37 => 'z',
38 => 'z',
39 => 'z',
40 => '=',
41 => 'o',
42 => 'o',
43 => 'o',
44 => '`',
45 => '=',
46 => 'e',
47 => 'z',
3200 => default
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment