Class: MoonTerm
- Inherits:
-
Object
- Object
- MoonTerm
- Defined in:
- lib/moon.rb
Overview
MAIN ###
Constant Summary collapse
- DAY_NAMES =
[ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]
- MOONS =
{ new: ["\u{1F311}", "New Moon", "New"], waxing_crescent: ["\u{1F312}", "Waxing Crescent", "WxC"], first_quarter: ["\u{1F313}", "First Quarter", "FQ"], waxing_gibbous: ["\u{1F314}", "Waxing Gibbous", "WxG"], full: ["\u{1F315}", "Full Moon", "Full"], waning_gibbous: ["\u{1F316}", "Waning Gibbous", "WnG"], last_quarter: ["\u{1F317}", "Last Quarter", "LQ"], waning_crescent: ["\u{1F318}", "Waning Crescent", "WnC"] }
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
Instance Method Summary collapse
- #help_text ⇒ Object
-
#initialize(date = MoonDate.today) ⇒ MoonTerm
constructor
A new instance of MoonTerm.
- #moon_day ⇒ Object
- #moon_month ⇒ Object
- #moon_week ⇒ Object
Constructor Details
#initialize(date = MoonDate.today) ⇒ MoonTerm
Returns a new instance of MoonTerm.
36 37 38 |
# File 'lib/moon.rb', line 36 def initialize(date=MoonDate.today) @date = date end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
10 11 12 |
# File 'lib/moon.rb', line 10 def date @date end |
Instance Method Details
#help_text ⇒ Object
76 77 78 |
# File 'lib/moon.rb', line 76 def help_text "\nUsage: moon [today | week | month | help | -h]" end |
#moon_day ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/moon.rb', line 40 def moon_day header_string = "\n" + center_string("The Moon today (#{@date.strftime("%a, %b %e")}):") + "\n\n" phase_string = center_string($pastel.bold(MOONS[@date.moon_phase][1])) + "\n" moon_icon = center_string(MOONS[@date.moon_phase][0]) + "\n" header_string + phase_string + moon_icon end |
#moon_month ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/moon.rb', line 63 def moon_month table = TTY::Table.new(DAY_NAMES, []) days = @date.month_days(true).map do |day| day.nil? ? day : (day == @date) ? "#{$pastel.bold(day.strftime("%d"))}\n#{MOONS[day.moon_phase][0]}" : "#{day.strftime("%d")}\n#{MOONS[day.moon_phase][0]}" end weeks = days.each_slice(7).to_a weeks.each { |week| table << week } "\n" + center_string($pastel.bold("Moon Phases for #{@date.strftime("%B %Y")}")) + "\n\n" + center_table(table.render(multiline: true, alignment: [:center], padding:[0, 1, 0, 1])) end |
#moon_week ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/moon.rb', line 48 def moon_week table = TTY::Table.new(DAY_NAMES, []) title = "\n" + center_string($pastel.bold("Moon Phases for the #{number_ord(@date.current_week)} week of #{@date.strftime("%B")}")) + "\n\n" table << @date.month_days(true).each_slice(7).to_a[@date.current_week - 1].map do |day| if day == @date then $pastel.bold(day.strftime("%b %e")) elsif !day.nil? then day.strftime("%b %e") else nil end end table << @date.week_days(true).map { |day| day.nil? ? day : MOONS[day.moon_phase][0] } title + center_table(table.render(multiline: true, alignment: [:center], padding: [0, 2, 0, 2])) end |