Class: TicketSharing::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/ticket_sharing/time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Time

Returns a new instance of Time.



8
9
10
11
12
13
14
15
16
17
# File 'lib/ticket_sharing/time.rb', line 8

def initialize(value)
  case value
  when ::Time, nil
    @value = value
  when String
    @value = ::Time.parse(value.dup)
  else
    raise "Invalid value provided for requested_at"
  end
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



19
20
21
# File 'lib/ticket_sharing/time.rb', line 19

def as_json(_options = {})
  @value ? @value.strftime('%Y-%m-%d %H:%M:%S %z') : nil
end

#to_json(_options = {}) ⇒ Object



23
24
25
# File 'lib/ticket_sharing/time.rb', line 23

def to_json(_options = {})
  JsonSupport.encode(as_json)
end

#to_timeObject

Support method to play well with active record



28
29
30
# File 'lib/ticket_sharing/time.rb', line 28

def to_time
  value
end