6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/shengxiao/finder.rb', line 6
def sign_for(date)
date = Date.parse(date) unless date.is_a?(Date)
year = date.year
parse_data_from_file if @data.empty?
year_data = get_year_data(year)
raise "Date should be specified in the given range: "\
"#{@data_start} - #{@data_end}. "\
"You specified: #{date}." unless year_data
year_start_date = Date.parse("#{year_data['start_date']} #{year}")
if date < year_start_date
year_data = get_year_data(year-1)
raise "Given date should be no earlier than #{@data_start}. "\
"You specified: #{date}." unless year_data
end
sign = year_data["sign"]
I18n.t("shengxiao.signs.#{sign}")
end
|