Class: TwitterCldr::Shared::DayPeriods

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/twitter_cldr/shared/day_periods.rb

Defined Under Namespace

Classes: AtRule, FromRule, Rule, Timestamp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale, rule_set = :default) ⇒ DayPeriods

Returns a new instance of DayPeriods.



124
125
126
127
# File 'lib/twitter_cldr/shared/day_periods.rb', line 124

def initialize(locale, rule_set = :default)
  @locale = locale
  @rule_set = rule_set
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



116
117
118
# File 'lib/twitter_cldr/shared/day_periods.rb', line 116

def locale
  @locale
end

#rule_setObject (readonly)

Returns the value of attribute rule_set.



116
117
118
# File 'lib/twitter_cldr/shared/day_periods.rb', line 116

def rule_set
  @rule_set
end

Class Method Details

.instance(locale) ⇒ Object



105
106
107
# File 'lib/twitter_cldr/shared/day_periods.rb', line 105

def instance(locale)
  instance_cache[locale] ||= new(locale)
end

Instance Method Details

#period_type_for(time) ⇒ Object



118
119
120
121
122
# File 'lib/twitter_cldr/shared/day_periods.rb', line 118

def period_type_for(time)
  timestamp = Timestamp.new(time.hour, time.min, time.sec)
  rule = rules.find { |rule| rule.matches?(timestamp) }
  rule.name
end