Class: Journey

Inherits:
Object
  • Object
show all
Defined in:
lib/flickru/journey.rb

Instance Method Summary collapse

Constructor Details

#initialize(destination) ⇒ Journey

Returns a new instance of Journey.



6
7
8
9
10
11
12
13
# File 'lib/flickru/journey.rb', line 6

def initialize destination
  Ruby.assert("destination >= 0") { destination >= 0 }

  @distance    = destination
  @destination = destination
  @beginning   = Time.now
  @current     = Time.now
end

Instance Method Details

#distanceObject



26
27
28
# File 'lib/flickru/journey.rb', line 26

def distance
  @distance
end

#elapsedObject



30
31
32
# File 'lib/flickru/journey.rb', line 30

def elapsed
  @current - @beginning
end

#etaObject

seconds



34
35
36
# File 'lib/flickru/journey.rb', line 34

def eta # seconds
  @distance * elapsed / progress 
end

#progressObject



22
23
24
# File 'lib/flickru/journey.rb', line 22

def progress
  @destination - @distance
end

#take(step) ⇒ Object



15
16
17
18
19
20
# File 'lib/flickru/journey.rb', line 15

def take step
  Ruby.assert("@distance >= step") { @distance >= step }

  @distance -= step
  @current   = Time.now
end