lib/fat_period/period.rb
# Return a string representing this Period using compact format for years,
# halves, quarters, or months that represent a whole period; otherwise, just
# format the period as 'YYYY-MM-DD to YYYY-MM-DD'.
#
# @example
#   Period.new('2016-01-01', '2016-03-31') #=> '2016-1Q'
#   Period.new('2016-01-01', '2016-12-31') #=> '2016'
#   Period.new('2016-01-01', '2016-11-30') #=> '2016-01-01 to 2016-11-30'
#
# @return [String] concise representation of Period
Return a string representing this Period using compact format for years,
halves, quarters, or months that represent a whole period; otherwise, just
format the period as 'YYYY-MM-DD to YYYY-MM-DD'.
Return a string representing this Period using compact format for years halves quarters or months that represent a whole period ; otherwise just format the period as ' YYYY - MM - DD to YYYY - MM - DD ' .
def to_s
    if first.beginning_of_year? && last.end_of_year? && first.year == last.year
      first.year.to_s
    elsif first.beginning_of_half? &&
          last.end_of_half? &&
          first.year == last.year &&
          first.half == last.half
      "#{first.year}-#{first.half}H"
    elsif first.beginning_of_quarter? &&
          last.end_of_quarter? &&
          first.year == last.year &&
          first.quarter == last.quarter
      "#{first.year}-#{first.quarter}Q"
    elsif first.beginning_of_month? &&
          last.end_of_month? &&
          first.year == last.year &&
          first.month == last.month
      "#{first.year}-%02d" % first.month
    else
      "#{first.iso} to #{last.iso}"
    end
  end
def to_s if first . beginning_of_year? && last . end_of_year? && first . year == last . year first . year . to_s elsif first . beginning_of_half? && last . end_of_half? && first . year == last . year && first . half == last . half "#{first.year}-#{first.half}H" elsif first . beginning_of_quarter? && last . end_of_quarter? && first . year == last . year && first . quarter == last . quarter "#{first.year}-#{first.quarter}Q" elsif first . beginning_of_month? && last . end_of_month? && first . year == last . year && first . month == last . month "#{first.year}-%02d" % first . month else "#{first.iso} to #{last.iso}" end end
Return a string representing this Period using compact format for years,
halves, quarters, or months that represent a whole period; otherwise, just
format the period as 'YYYY-MM-DD to YYYY-MM-DD'.
Return a string representing this Period using compact format for years halves quarters or months that represent a whole period ; otherwise just format the period as ' YYYY - MM - DD to YYYY - MM - DD ' .
concise representation of Period
concise representation of Period
String
example
None