Class: TicketSharing::Time
- Inherits:
-
Object
- Object
- TicketSharing::Time
- Defined in:
- lib/ticket_sharing/time.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(value) ⇒ Time
constructor
A new instance of Time.
- #to_json(_options = {}) ⇒ Object
-
#to_time ⇒ Object
Support method to play well with active record.
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
#value ⇒ Object (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( = {}) @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( = {}) JsonSupport.encode(as_json) end |
#to_time ⇒ Object
Support method to play well with active record
28 29 30 |
# File 'lib/ticket_sharing/time.rb', line 28 def to_time value end |