38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/astro_helper.rb', line 38
def init_calc(calc, *args)
case args.size
when 1
ary = args.first.dup
tz = ary.shift
tz = tz["name"] if tz.respond_to?(:[])
tz = tz.name if tz.respond_to?(:name)
calc.tz = tz
time = ary.shift
if time.respond_to?(:jd)
time = time.jd
else
time = datetime_to_jd(time) unless time.is_a?(Numeric)
end
calc.jd = time
calc.set_topo(*ary[0...3])
calc.datetime = DateTime.now if calc.jd.zero?
calc
else
year, month, day, hour, minute, location, name = *args
second = ((minute - minute.floor) * 60).round
minute = minute.floor
results = Geocoder.search(location)
calc.set_topo(results.first.latitude, results.first.longitude)
tz = results.first.send(:properties)["timezone"]
calc.tz = tz["name"]
calc.datetime = TZInfo::Timezone.get(tz["name"]).local_time(year, month, day, hour, minute, second, 10/600r).utc
calc.to_a + [location, name]
end
end
|