class CarbonDate::Formatter

Responsible for formatting a CarbonDate::Date as a human-readable string. Used when CarbonDate::Date#to_s is called.

You can extend Formatter to create your own custom output for dates.

class MyCustomFormatter < CarbonDate::Formatter
  def year(date)
    # ...
  end
 # ...
end

Then, to use your custom formatter, simply do:

CarbonDate::Date.formatter = MyCustomFormatter.new

All subsequent dates will be formatted using your custom formatter. Implementations of Formatter need to override all of the following methods:

All of the above methods take a CarbonDate::Date as a parameter.

Public Instance Methods

date_to_string(date) click to toggle source

Formats a CarbonDate::Date object as a human-readable string

# File lib/carbon_date/formatter.rb, line 38
def date_to_string(date)
  precision = date.precision
  if CarbonDate::Date::PRECISION.include? precision # Call me paranoid: whitelist the available functions
    public_send(precision, date)
  else
    raise StandardError.new("Unrecognized precision: #{precision}")
  end
end