Class: PopCap::Formatters::Date

Inherits:
Formatter show all
Defined in:
lib/pop_cap/formatters/date.rb

Overview

Public: This is a formatter for the date tag. It is used to match and return the year.

date - The date can be sent as a string or integer. options - An optional hash for a start & end date range.

The start_date defaults to 1800, end_date defaults
to 2100.

Instance Attribute Summary

Attributes inherited from Formatter

#options, #value

Instance Method Summary collapse

Methods inherited from Formatter

format, #initialize, subclasses, subclasses_demodulized

Constructor Details

This class inherits a constructor from PopCap::Formatters::Formatter

Instance Method Details

#end_dateObject



30
31
32
# File 'lib/pop_cap/formatters/date.rb', line 30

def end_date
  options[:end_date] || 2100
end

#formatObject

Public: This method returns a year if it is matched.

Examples

date = Date.new('October 5, 1975')
date.format
# => '1975'


21
22
23
24
# File 'lib/pop_cap/formatters/date.rb', line 21

def format
  return unless ( date_match && within_date_range? )
  @match[0].to_i
end

#start_dateObject



26
27
28
# File 'lib/pop_cap/formatters/date.rb', line 26

def start_date
  options[:start_date] || 1800
end