Class: TwitterCldr::Shared::DayPeriods::FromRule

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

Instance Attribute Summary

Attributes inherited from Rule

#name, #params

Instance Method Summary collapse

Methods inherited from Rule

create, #initialize

Constructor Details

This class inherits a constructor from TwitterCldr::Shared::DayPeriods::Rule

Instance Method Details

#<=>(other) ⇒ Object



47
48
49
50
51
# File 'lib/twitter_cldr/shared/day_periods.rb', line 47

def <=>(other)
  return 1 if other.params[:at]

  timespan <=> other.timespan
end

#beforeObject



67
68
69
70
71
# File 'lib/twitter_cldr/shared/day_periods.rb', line 67

def before
  @before ||= Timestamp.new(
    params[:before][:hour], params[:before][:min], 0
  )
end

#fromObject



61
62
63
64
65
# File 'lib/twitter_cldr/shared/day_periods.rb', line 61

def from
  @from ||= Timestamp.new(
    params[:from][:hour], params[:from][:min], 0
  )
end

#matches?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'lib/twitter_cldr/shared/day_periods.rb', line 73

def matches?(timestamp)
  if from > before
    timestamp >= from || timestamp < before
  else
    timestamp >= from && timestamp < before
  end
end

#timespanObject



53
54
55
56
57
58
59
# File 'lib/twitter_cldr/shared/day_periods.rb', line 53

def timespan
  @timespan ||= if from > before
    (24 - from.to_f) + before.to_f
  else
    before.to_f - from.to_f
  end
end