Class: Code::Object::Time

Inherits:
Code::Object show all
Defined in:
lib/code/object/time.rb

Constant Summary collapse

DEFAULT_ZONE =
"Etc/UTC"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Code::Object

#<=>, #==, #call, code_and_operator, #code_and_operator, #code_different, code_different, code_equal_equal, #code_equal_equal, #code_equal_equal_equal, code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, code_inclusive_range, #code_inclusive_range, code_or_operator, #code_or_operator, code_self, #code_self, code_to_string, #code_to_string, falsy?, #falsy?, hash, #hash, maybe, multi_fetch, #multi_fetch, repeat, sig, #sig, to_s, truthy?, #truthy?, |

Constructor Details

#initialize(time) ⇒ Time

Returns a new instance of Time.



10
11
12
# File 'lib/code/object/time.rb', line 10

def initialize(time)
  @raw = time
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/code/object/time.rb', line 8

def raw
  @raw
end

Class Method Details

.call(**args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/code/object/time.rb', line 18

def self.call(**args)
  operator = args.fetch(:operator, nil)

  case operator.to_s
  when "tomorrow"
    sig(args)
    code_tomorrow
  else
    super
  end
end

.code_tomorrowObject



30
31
32
33
# File 'lib/code/object/time.rb', line 30

def self.code_tomorrow
  ::Time.zone ||= DEFAULT_ZONE
  new(::Time.zone.tomorrow.beginning_of_day)
end

.nameObject



14
15
16
# File 'lib/code/object/time.rb', line 14

def self.name
  "Time"
end

Instance Method Details

#inspectObject



35
36
37
# File 'lib/code/object/time.rb', line 35

def inspect
  to_s
end

#to_sObject



39
40
41
# File 'lib/code/object/time.rb', line 39

def to_s
  raw.to_s
end