Class: Spill::Window
- Inherits:
-
Data
- Object
- Data
- Spill::Window
- Defined in:
- lib/spill/window.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#since ⇒ Object
readonly
Returns the value of attribute since.
Class Method Summary collapse
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label
4 5 6 |
# File 'lib/spill/window.rb', line 4 def label @label end |
#since ⇒ Object (readonly)
Returns the value of attribute since
4 5 6 |
# File 'lib/spill/window.rb', line 4 def since @since end |
Class Method Details
.default(now: Time.now) ⇒ Object
5 6 7 |
# File 'lib/spill/window.rb', line 5 def self.default(now: Time.now) new(since: midnight(now) - 86_400, label: "today + yesterday") end |
.midnight(time) ⇒ Object
23 24 25 |
# File 'lib/spill/window.rb', line 23 def self.midnight(time) Time.new(time.year, time.month, time.day) end |
.parse(expr, now: Time.now) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spill/window.rb', line 9 def self.parse(expr, now: Time.now) text = expr.strip since = case text when "today" then midnight(now) when "yesterday" then midnight(now) - 86_400 when /\A(\d+)\s+hours?\s+ago\z/ then now - ($1.to_i * 3_600) when /\A(\d+)\s+days?\s+ago\z/ then now - ($1.to_i * 86_400) when /\A(\d+)\s+weeks?\s+ago\z/ then now - ($1.to_i * 7 * 86_400) else Time.parse(text) end new(since: since, label: text) end |