Class: CS::Time
- Inherits:
-
Object
show all
- Defined in:
- lib/cs/time.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(time = nil) ⇒ Time
Returns a new instance of Time.
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/cs/time.rb', line 6
def initialize(time=nil)
if time.nil?
@time = ::Time.new
elsif time.instance_of?(::Time)
@time = time
elsif time.kind_of?(::Numeric)
@time = ::Time.at(time)
elsif time.class.to_s == "TimeLord::Period"
@time = ::Time.at(time.beginning)
else
@time = time.to_time
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
41
42
43
|
# File 'lib/cs/time.rb', line 41
def method_missing(method, *args, &block)
@time.send(method, *args, &block)
end
|
Instance Attribute Details
#time ⇒ Object
Returns the value of attribute time.
4
5
6
|
# File 'lib/cs/time.rb', line 4
def time
@time
end
|
Class Method Details
.at(epoch) ⇒ Object
20
21
22
|
# File 'lib/cs/time.rb', line 20
def self.at(epoch)
::Time.at(epoch)
end
|
.now ⇒ Object
24
25
26
|
# File 'lib/cs/time.rb', line 24
def self.now
::Time.now
end
|
Instance Method Details
#inspect ⇒ Object
36
37
38
|
# File 'lib/cs/time.rb', line 36
def inspect
@time.inspect
end
|
#to_f ⇒ Object
28
29
30
|
# File 'lib/cs/time.rb', line 28
def to_f
@time.to_f.round(3)
end
|
#to_s ⇒ Object
32
33
34
|
# File 'lib/cs/time.rb', line 32
def to_s
@time.to_s
end
|