require 'solareventcalculator' module CalendarHelper def planet_for_day(weekday) { "Sunday" => "Sun", "Monday" => "Moon", "Tuesday" => "Mars", "Wednesday" => "Mercury", "Thursday" => "Jupiter", "Friday" => "Venus", "Saturday" => "Saturn" }[weekday] end def moon_phase_matches?(date) # Implement your moon phase calculation logic here # Return true if the current moon phase matches the required phase for spirits # You might want to use a gem like ruby-moon for accurate calculations true # Placeholder return value end def celestial_emoji(planet) { "Sun" => "☉", "Moon" => "☽", "Mars" => "♂", "Mercury" => "☿", "Jupiter" => "♃", "Venus" => "♀", "Saturn" => "♄" }[planet] end def current_time_valid?(date) rank = Rank.find_by(planet: planet_for_day(date.strftime("%A"))) return false unless rank case rank.time.downcase when "anytime" true when "dawn to sunrise" current_hour = Time.now.hour (4..6).include?(current_hour) when "sunrise to noon" current_hour = Time.now.hour (6..12).include?(current_hour) when "3pm to sunrise" current_hour = Time.now.hour (15..23).include?(current_hour) || (0..6).include?(current_hour) when "anytime excluding twilight" current_hour = Time.now.hour !(4..6).include?(current_hour) && !(17..19).include?(current_hour) when "anytime in a desolate place" true # This would need additional context to determine when "on great occasions" # You might want to add logic here to determine what constitutes a "great occasion" true else true # Default to allowing if we don't recognize the time restriction end end def time_requirement_icon(time) icon = case time.downcase when /sunrise/ "🌅" when /dawn/ "🌄" when /noon/ "☀️" when /twilight/ "🌆" when /anytime/ "⌛" when /desolate/ "🏚️" when /great occasions/ "👑" else "⏰" end content_tag :span, icon, class: "time-icon", title: time end def sunrise_time(date) calculator = SolarEventCalculator.new(date, latitude, longitude) sunrise = calculator.compute_official_sunrise format_time_with_date(sunrise, date) end def sunset_time(date) calculator = SolarEventCalculator.new(date, latitude, longitude) sunset = calculator.compute_official_sunset format_time_with_date(sunset, date) end private def format_time_with_date(time, date) local_time = time.in_time_zone "#{local_time.strftime('%H:%M')} #{date.strftime('%d %b')}" end def latitude # Replace with your location's latitude 48.8566 # Example: Paris end def longitude # Replace with your location's longitude 2.3522 # Example: Paris end end