Class: Clock

Inherits:
Time
  • Object
show all
Includes:
Comparable
Defined in:
lib/clock.rb,
lib/MockAWS/clock.rb

Overview

Used to mock Time

Constant Summary collapse

@@current_time =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time) ⇒ Clock

Returns a new instance of Clock.



10
11
12
# File 'lib/MockAWS/clock.rb', line 10

def initialize(time)
  @time = time
end

Instance Attribute Details

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/MockAWS/clock.rb', line 5

def time
  @time
end

Class Method Details

.at(time) ⇒ Object



14
15
16
# File 'lib/MockAWS/clock.rb', line 14

def Clock.at(time)
  Clock.new(time)
end

.hourObject



22
23
24
# File 'lib/MockAWS/clock.rb', line 22

def Clock.hour
  (@@current_time/3600).floor
end

.nowObject



18
19
20
# File 'lib/MockAWS/clock.rb', line 18

def Clock.now
  Clock.new(@@current_time)
end

.parse(tm) ⇒ Object



54
55
56
# File 'lib/MockAWS/clock.rb', line 54

def Clock.parse(tm)
  Clock.new(Time.parse(tm).to_i)
end

.resetObject

testing



60
61
62
# File 'lib/MockAWS/clock.rb', line 60

def Clock.reset
  @@current_time = 0
end

.set(numeric) ⇒ Object



64
65
66
# File 'lib/MockAWS/clock.rb', line 64

def Clock.set(numeric)
  @@current_time = numeric
end

.sleep(numeric = 0) ⇒ Object



6
7
8
# File 'lib/clock.rb', line 6

def Clock.sleep(numeric = 0)
  Kernel.sleep numeric
end

.xmlschema(tm) ⇒ Object



50
51
52
# File 'lib/MockAWS/clock.rb', line 50

def Clock.xmlschema(tm)
  Clock.new(Time.xmlschema(tm).to_i)
end

Instance Method Details

#+(time) ⇒ Object



30
31
32
# File 'lib/MockAWS/clock.rb', line 30

def +(time)
  Clock.new(time + @time)
end

#-(clock) ⇒ Object



34
35
36
# File 'lib/MockAWS/clock.rb', line 34

def -(clock)
  @time - clock.time
end

#<=>(other) ⇒ Object



38
39
40
# File 'lib/MockAWS/clock.rb', line 38

def <=>(other)
  @time <=> other.time
end

#strftime(format) ⇒ Object



42
43
44
# File 'lib/MockAWS/clock.rb', line 42

def strftime(format)
  @time.to_s
end

#to_sObject



26
27
28
# File 'lib/MockAWS/clock.rb', line 26

def to_s
  @time.to_s
end