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


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/parse/datatypes.rb', line 76

def initialize(data)
  if data.respond_to?(:iso8601)
    @value = data
  elsif data.is_a? Hash
    @value = DateTime.parse data["iso"]
  elsif data.is_a? String
    @value = DateTime.parse data
  else
    raise "data doesn't act like time #{data.inspect}"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


103
104
105
106
107
108
109
# File 'lib/parse/datatypes.rb', line 103

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


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

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object


99
100
101
# File 'lib/parse/datatypes.rb', line 99

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

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

Returns:

  • (Boolean)

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

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

#hashObject


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

def hash
  value.hash
end

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

Returns:

  • (Boolean)

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

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

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


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

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

#to_json(*a) ⇒ Object


123
124
125
# File 'lib/parse/datatypes.rb', line 123

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