Class: Parse::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/datatypes.rb

Overview

Date


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Date

Returns a new instance of Date.



63
64
65
66
67
68
69
70
71
# File 'lib/parse/datatypes.rb', line 63

def initialize(data)
  if data.is_a? DateTime
    @value = data
  elsif data.is_a? Hash
    @value = DateTime.parse data["iso"]
  elsif data.is_a? String
    @value = DateTime.parse data
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



88
89
90
91
92
93
94
# File 'lib/parse/datatypes.rb', line 88

def method_missing(method, *args, &block)
  if value.respond_to?(method)
    value.send(method, *args, &block)
  else
    super(method)
  end
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



61
62
63
# File 'lib/parse/datatypes.rb', line 61

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



84
85
86
# File 'lib/parse/datatypes.rb', line 84

def <=>(other)
  value <=> other.value
end

#as_json(*a) ⇒ Object



100
101
102
103
104
105
# File 'lib/parse/datatypes.rb', line 100

def as_json(*a)
  {
      Protocol::KEY_TYPE => Protocol::TYPE_DATE,
      "iso"              => value.iso8601(3)
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/parse/datatypes.rb', line 73

def eql?(other)
  self.class.equal?(other.class) &&
    value == other.value
end

#hashObject



80
81
82
# File 'lib/parse/datatypes.rb', line 80

def hash
  value.hash
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/parse/datatypes.rb', line 96

def respond_to?(method, include_private = false)
  super || value.respond_to?(method, include_private)
end

#to_json(*a) ⇒ Object



107
108
109
# File 'lib/parse/datatypes.rb', line 107

def to_json(*a)
    as_json.to_json(*a)
end