Class: TwitterCldr::DataReaders::TimespanDataReader

Inherits:
DataReader
  • Object
show all
Defined in:
lib/twitter_cldr/data_readers/timespan_data_reader.rb

Constant Summary collapse

DEFAULT_DIRECTION =
:ago
DEFAULT_TYPE =
:default
VALID_FIELDS =
[:second, :minute, :hour, :day, :week, :month, :year]
BASE_PATH =
[:fields]

Instance Attribute Summary collapse

Attributes inherited from DataReader

#locale

Instance Method Summary collapse

Methods inherited from DataReader

#pattern_at_path

Constructor Details

#initialize(locale, seconds, options = {}) ⇒ TimespanDataReader

Returns a new instance of TimespanDataReader.



16
17
18
19
20
21
22
23
24
25
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 16

def initialize(locale, seconds, options = {})
  super(locale)

  @type = options[:type] || DEFAULT_TYPE
  @direction = options[:direction] || DEFAULT_DIRECTION
  @unit = options[:unit]

  @plural_rule = options[:plural_rule] ||
    TwitterCldr::Formatters::Plurals::Rules.rule_for(seconds, locale)
end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



14
15
16
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 14

def direction
  @direction
end

#plural_ruleObject (readonly)

Returns the value of attribute plural_rule.



14
15
16
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 14

def plural_rule
  @plural_rule
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 14

def type
  @type
end

#unitObject (readonly)

Returns the value of attribute unit.



14
15
16
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 14

def unit
  @unit
end

Instance Method Details

#formatterObject



35
36
37
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 35

def formatter
  @formatter ||= TwitterCldr::Formatters::TimespanFormatter.new(self)
end

#patternObject



27
28
29
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 27

def pattern
  traverse(path)
end

#tokenizerObject



31
32
33
# File 'lib/twitter_cldr/data_readers/timespan_data_reader.rb', line 31

def tokenizer
  @tokenizer ||= TwitterCldr::Tokenizers::TimespanTokenizer.new(self)
end