Class: TwitterCldr::Localized::LocalizedTimespan
- Inherits:
-
LocalizedObject
- Object
- LocalizedObject
- TwitterCldr::Localized::LocalizedTimespan
- Defined in:
- lib/twitter_cldr/localized/localized_timespan.rb
Constant Summary collapse
- DEFAULT_TYPE =
:default
- APPROXIMATE_MULTIPLIER =
0.75
- TIME_IN_SECONDS =
{ second: 1, minute: 60, hour: 3600, day: 86400, week: 604800, month: 2629743.83, year: 31556926 }
Instance Attribute Summary
Attributes inherited from LocalizedObject
#base_obj, #formatter, #locale
Instance Method Summary collapse
-
#initialize(seconds, options = {}) ⇒ LocalizedTimespan
constructor
A new instance of LocalizedTimespan.
- #to_s(options = {}) ⇒ Object
Methods inherited from LocalizedObject
Constructor Details
#initialize(seconds, options = {}) ⇒ LocalizedTimespan
Returns a new instance of LocalizedTimespan.
23 24 25 |
# File 'lib/twitter_cldr/localized/localized_timespan.rb', line 23 def initialize(seconds, = {}) super(seconds, [:locale] || TwitterCldr.locale, ) end |
Instance Method Details
#to_s(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/twitter_cldr/localized/localized_timespan.rb', line 27 def to_s( = {}) unit = [:unit] || calculate_unit(base_obj.abs, ) direction = [:direction] || (base_obj < 0 ? :ago : :until) type = [:type] || DEFAULT_TYPE number = calculate_time(base_obj, unit) data_reader = TwitterCldr::DataReaders::TimespanDataReader.new(locale, number, { unit: unit, direction: direction, type: type }) tokens = data_reader.tokenizer.tokenize(data_reader.pattern) data_reader.formatter.format(tokens, number, ) end |