Class: TerminalCalendar::Month::CalendarDay

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal_calendar/month/calendar_day.rb

Direct Known Subclasses

NullDay

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, pastel = Pastel.new) ⇒ CalendarDay

Returns a new instance of CalendarDay.

Parameters:

  • date (Date)

    The date to be assigned to this calendar day

  • pastel (Pastel) (defaults to: Pastel.new)

    The pastel object to use for decorating text



13
14
15
16
# File 'lib/terminal_calendar/month/calendar_day.rb', line 13

def initialize(date, pastel=Pastel.new)
  @date = date
  @pastel = pastel
end

Instance Attribute Details

#dateDate (readonly)

Returns The date for this calendar day.

Returns:

  • (Date)

    The date for this calendar day



9
10
11
# File 'lib/terminal_calendar/month/calendar_day.rb', line 9

def date
  @date
end

#pastelPastel (readonly)

Returns The pastel object to use for decorating text.

Returns:

  • (Pastel)

    The pastel object to use for decorating text



6
7
8
# File 'lib/terminal_calendar/month/calendar_day.rb', line 6

def pastel
  @pastel
end

Instance Method Details

#dayInteger

Returns the day of the date.

Returns:

  • (Integer)

    The day of the date.



46
47
48
# File 'lib/terminal_calendar/month/calendar_day.rb', line 46

def day
  date.day
end

#null?false

Returns whether the object is null or not.

Returns:

  • (false)

    Returns false.



39
40
41
# File 'lib/terminal_calendar/month/calendar_day.rb', line 39

def null?
  false
end

#renderString Also known as: to_s

Renders the day as a string.

Returns:

  • (String)

    the day as a string



20
21
22
23
24
25
# File 'lib/terminal_calendar/month/calendar_day.rb', line 20

def render
  as_string = day.to_s
  as_string = " #{as_string}" if as_string.length == 1
  as_string = pastel.red(as_string) if today?
  as_string
end

#today?Boolean

Determines if the given date is today.

Returns:

  • (Boolean)

    Returns true if the date is today, false otherwise.



32
33
34
# File 'lib/terminal_calendar/month/calendar_day.rb', line 32

def today?
  date == Date.today
end