Class: TwitterCldr::DataReaders::TimespanDataReader
- Inherits:
-
DataReader
- Object
- DataReader
- TwitterCldr::DataReaders::TimespanDataReader
- Defined in:
- lib/twitter_cldr/data_readers/timespan_data_reader.rb
Constant Summary collapse
- DEFAULT_DIRECTION =
:none
- DEFAULT_TYPE =
:default
- VALID_UNITS =
[:second, :minute, :hour, :day, :week, :month, :year]
- BASE_PATH =
[:units]
- PATHS =
{ :ago => { :default => :'hour-past', :second => :'second-past', :minute => :'minute-past', :hour => :'hour-past', :day => :'day-past', :week => :'week-past', :month => :'month-past', :year => :'year-past' }, :until => { :default => :'hour-future', :second => :'second-future', :minute => :'minute-future', :hour => :'hour-future', :day => :'day-future', :week => :'week-future', :month => :'month-future', :year => :'year-future' }, :none => { :default => :second, :second => :second, :minute => :minute, :hour => :hour, :day => :day, :week => :week, :month => :month, :year => :year } }
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Attributes inherited from DataReader
Class Method Summary collapse
Instance Method Summary collapse
- #formatter ⇒ Object
-
#initialize(locale, seconds, options = {}) ⇒ TimespanDataReader
constructor
A new instance of TimespanDataReader.
-
#pattern ⇒ Object
type is stuff like :abbreviated, etc.
- #tokenizer ⇒ Object
Methods inherited from DataReader
Constructor Details
#initialize(locale, seconds, options = {}) ⇒ TimespanDataReader
Returns a new instance of TimespanDataReader.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 50 def initialize(locale, seconds, = {}) super(locale) @type = [:type] || DEFAULT_TYPE @direction = [:direction] || DEFAULT_DIRECTION @unit = [:unit] @rule = [:rule] || TwitterCldr::Formatters::Plurals::Rules.rule_for(seconds, locale) end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
48 49 50 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 48 def direction @direction end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
48 49 50 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 48 def rule @rule end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
48 49 50 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 48 def type @type end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
48 49 50 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 48 def unit @unit end |
Class Method Details
.all_types_for(locale, unit, direction) ⇒ Object
110 111 112 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 110 def all_types_for(locale, unit, direction) TwitterCldr::Utils.traverse_hash(resource_for_locale(locale), BASE_PATH + [PATHS[direction][unit]]).keys end |
.resource_for_locale(locale) ⇒ Object
114 115 116 117 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 114 def resource_for_locale(locale) @resources ||= {} @resources[locale] ||= TwitterCldr.get_locale_resource(locale, :units)[TwitterCldr.convert_locale(locale)] end |
Instance Method Details
#formatter ⇒ Object
81 82 83 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 81 def formatter TwitterCldr::Formatters::TimespanFormatter.new(self) end |
#pattern ⇒ Object
type is stuff like :abbreviated, etc
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 62 def pattern path = full_path_for(direction, unit, type) available = traverse(path) pluralization = pluralization_for(rule, available) if available.include?(pluralization) path << pluralization else return [] unless available.keys.first path << available.keys.first end traverse(path) end |
#tokenizer ⇒ Object
77 78 79 |
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 77 def tokenizer TwitterCldr::Tokenizers::TimespanTokenizer.new(self) end |