Class: Ddate::Formatter
- Inherits:
-
Object
- Object
- Ddate::Formatter
- Defined in:
- lib/ddate/formatter.rb
Constant Summary collapse
- STTIBS_RE =
%r|%{(.*?)%}|
- SPLIT_STOP =
'%%N'
- DEFAULT_FORMAT =
'%{%A, %B the %e%}, YOLD %Y.%N Celebrate %H!'
Instance Attribute Summary collapse
-
#standard ⇒ Object
readonly
Returns the value of attribute standard.
-
#sttibs ⇒ Object
readonly
Returns the value of attribute sttibs.
Instance Method Summary collapse
- #create_format_string_from(format_string) ⇒ Object
-
#initialize(format = nil) ⇒ Formatter
constructor
A new instance of Formatter.
- #split(key) ⇒ Object
Constructor Details
#initialize(format = nil) ⇒ Formatter
Returns a new instance of Formatter.
12 13 14 15 16 |
# File 'lib/ddate/formatter.rb', line 12 def initialize(format = nil) format = DEFAULT_FORMAT if format.to_s.empty? @standard = create_format_string_from(format.gsub(STTIBS_RE){$1}) @sttibs = create_format_string_from(format.gsub(STTIBS_RE, '%{st_tibs_day}')) end |
Instance Attribute Details
#standard ⇒ Object (readonly)
Returns the value of attribute standard.
10 11 12 |
# File 'lib/ddate/formatter.rb', line 10 def standard @standard end |
#sttibs ⇒ Object (readonly)
Returns the value of attribute sttibs.
10 11 12 |
# File 'lib/ddate/formatter.rb', line 10 def sttibs @sttibs end |
Instance Method Details
#create_format_string_from(format_string) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ddate/formatter.rb', line 18 def create_format_string_from(format_string) format_string.gsub(/%[AaBbdeHNntY.X]/, { '%A' => '%{dayname}', '%a' => '%{dayname_short}', '%B' => '%{seasonname}', '%b' => '%{seasonname_short}', '%d' => '%{day}', '%e' => '%{dayth}', '%H' => '%{holiday}', '%N' => SPLIT_STOP, '%n' => "\n", '%t' => "\t", '%Y' => '%{year}', '%.' => '%{exclaim}', '%X' => '%{kill_bob}', } ) end |
#split(key) ⇒ Object
31 32 33 |
# File 'lib/ddate/formatter.rb', line 31 def split(key) send(key).split(SPLIT_STOP, 2) end |