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

#to_jsonObject



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

def to_json
  JsonSupport.encode(@value ? @value.strftime('%Y-%m-%d %H:%M:%S %z') : nil)
end

#to_timeObject

Support method to play well with active record



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

def to_time
  value
end