Class: Parse::ParseDate

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/parse/date.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#string_keyed_hash

Constructor Details

#initialize(hash = {}) ⇒ ParseDate

Returns a new instance of ParseDate.



12
13
14
15
16
# File 'lib/parse/date.rb', line 12

def initialize hash={}
  hash = string_keyed_hash hash
  @raw_hash = hash
  @time = ::Time.parse hash['iso'] if hash.has_key? 'iso'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



33
34
35
# File 'lib/parse/date.rb', line 33

def method_missing name, *args, &block
  @time.__send__ name, *args, &block
end

Class Method Details

.parse(str) ⇒ Object



7
8
9
# File 'lib/parse/date.rb', line 7

def parse str
  new :iso => str
end

Instance Method Details

#to_hObject



18
19
20
21
22
23
# File 'lib/parse/date.rb', line 18

def to_h
  {
    "__type" => "Date",
    "iso" => @time.strftime('%Y-%m-%dT%H:%M:%SZ')
  }
end

#to_json(*args) ⇒ Object



25
26
27
# File 'lib/parse/date.rb', line 25

def to_json *args
  to_h.to_json
end

#to_sObject



29
30
31
# File 'lib/parse/date.rb', line 29

def to_s
  to_json
end