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.



73
74
75
76
77
78
79
80
81
# File 'lib/parse/datatypes.rb', line 73

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



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

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.



71
72
73
# File 'lib/parse/datatypes.rb', line 71

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



94
95
96
# File 'lib/parse/datatypes.rb', line 94

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

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

Returns:

  • (Boolean)


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

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

#hashObject



90
91
92
# File 'lib/parse/datatypes.rb', line 90

def hash
  value.hash
end

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

Returns:

  • (Boolean)


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

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

#to_h(*a) ⇒ Object Also known as: as_json



110
111
112
113
114
115
# File 'lib/parse/datatypes.rb', line 110

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

#to_json(*a) ⇒ Object



118
119
120
# File 'lib/parse/datatypes.rb', line 118

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