class TwitterCldr::DataReaders::TimespanDataReader

Constants

BASE_PATH
DEFAULT_DIRECTION
DEFAULT_TYPE
VALID_FIELDS

Attributes

direction[R]
plural_rule[R]
type[R]
unit[R]

Public Class Methods

new(locale, seconds, options = {}) click to toggle source
# 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

Public Instance Methods

formatter() click to toggle source
# File lib/twitter_cldr/data_readers/timespan_data_reader.rb, line 35
def formatter
  @formatter ||= TwitterCldr::Formatters::TimespanFormatter.new(self)
end
pattern() click to toggle source
# File lib/twitter_cldr/data_readers/timespan_data_reader.rb, line 27
def pattern
  traverse(path)
end
tokenizer() click to toggle source
# File lib/twitter_cldr/data_readers/timespan_data_reader.rb, line 31
def tokenizer
  @tokenizer ||= TwitterCldr::Tokenizers::TimespanTokenizer.new(self)
end

Private Instance Methods

direction_field() click to toggle source
# File lib/twitter_cldr/data_readers/timespan_data_reader.rb, line 45
def direction_field
  case direction
    when :ago
      :past
    else
      :future
  end
end
path() click to toggle source
# File lib/twitter_cldr/data_readers/timespan_data_reader.rb, line 41
def path
  BASE_PATH + [type_field, :relative_time, direction_field, plural_rule]
end
resource() click to toggle source
# File lib/twitter_cldr/data_readers/timespan_data_reader.rb, line 63
def resource
  @resource ||= TwitterCldr.get_locale_resource(locale, :fields)[locale]
end
type_field() click to toggle source
# File lib/twitter_cldr/data_readers/timespan_data_reader.rb, line 54
def type_field
  case type
    when :default
      unit
    else
      :"#{unit}-#{type}"
  end
end