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.



53
54
55
56
57
58
59
60
61
# File 'lib/parse/datatypes.rb', line 53

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



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

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.



51
52
53
# File 'lib/parse/datatypes.rb', line 51

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#as_json(*a) ⇒ Object



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

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

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

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/parse/datatypes.rb', line 63

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

#hashObject



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

def hash
  value.hash
end

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

Returns:

  • (Boolean)


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

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

#to_json(*a) ⇒ Object



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

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

#to_sObject



78
79
80
# File 'lib/parse/datatypes.rb', line 78

def to_s
  value.to_s
end