Class: R18n::Locale
- Inherits:
-
Object
- Object
- R18n::Locale
- Defined in:
- lib/conjoin/i18n.rb
Overview
Instance Method Summary collapse
- #format_time_time(time, *params) ⇒ Object
-
#localize(obj, format = nil, *params) ⇒ Object
Convert
object
to String.
Instance Method Details
#format_time_time(time, *params) ⇒ Object
93 94 95 |
# File 'lib/conjoin/i18n.rb', line 93 def format_time_time time, *params format_time(time)[1..-1] end |
#localize(obj, format = nil, *params) ⇒ Object
Convert object
to String. It support Fixnum, Bignum, Float, Time, Date and DateTime.
For time classes you can set format
in standard strftime
form, :full
(“01 Jule, 2009”), :human
(“yesterday”), :standard
(“07/01/09”) or :month
for standalone month name. Default format is :standard
.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/conjoin/i18n.rb', line 69 def localize(obj, format = nil, *params) case obj when Integer format_integer(obj) when Float, BigDecimal format_float(obj.to_f) when Time, DateTime, Date return strftime(obj, format) if format.is_a? String return month_standalone[obj.month - 1] if :month == format return obj.to_s if :human == format and not params.first.is_a? I18n type = obj.is_a?(Date) ? 'date' : 'time' format = :standard unless format unless respond_to? "format_#{type}_#{format}" raise ArgumentError, "Unknown time formatter #{format}" end send "format_#{type}_#{format}", obj, *params else obj.to_s end end |