Created
August 24, 2012 03:43
-
-
Save mono0x/3445220 to your computer and use it in GitHub Desktop.
Horoscopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'date' | |
module Horoscopes | |
CONSTELLATIONS = [ | |
:capricorn, | |
:aquarius, | |
:pisces, | |
:aries, | |
:taurus, | |
:gemini, | |
:cancer, | |
:leo, | |
:virgo, | |
:libra, | |
:scorpius, | |
:sagittarius, | |
] | |
def self.astrology(date) | |
i = date.strftime('%m%d').to_i | |
return CONSTELLATIONS[ 0] if i <= 120 | |
return CONSTELLATIONS[ 1] if i <= 218 | |
return CONSTELLATIONS[ 2] if i <= 320 | |
return CONSTELLATIONS[ 3] if i <= 419 | |
return CONSTELLATIONS[ 4] if i <= 520 | |
return CONSTELLATIONS[ 5] if i <= 621 | |
return CONSTELLATIONS[ 6] if i <= 722 | |
return CONSTELLATIONS[ 7] if i <= 823 | |
return CONSTELLATIONS[ 8] if i <= 922 | |
return CONSTELLATIONS[ 9] if i <= 1023 | |
return CONSTELLATIONS[10] if i <= 1122 | |
return CONSTELLATIONS[11] if i <= 1221 | |
return CONSTELLATIONS[ 0] if i <= 1231 | |
raise 'must not happen' | |
end | |
def self.horoscopes(date = Date.today) | |
CONSTELLATIONS.shuffle(random: Random.new(date.strftime('%Y%m%d').to_i)) | |
end | |
end | |
japanese = { | |
capricorn: 'やぎ座', | |
aquarius: 'みずがめ座', | |
pisces: 'うお座', | |
aries: 'おひつじ座', | |
taurus: 'おうし座', | |
gemini: 'ふたご座', | |
cancer: 'かに座', | |
leo: 'しし座', | |
virgo: 'おとめ座', | |
libra: 'てんびん座', | |
scorpius: 'さそり座', | |
sagittarius: 'いて座', | |
} | |
d = Date.today | |
h = Horoscopes.horoscopes | |
a = Horoscopes.astrology(d) | |
p h, d, a, japanese[a], h.find_index {|_| _ == a } + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment