Class: Parse::Date

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

Overview

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
82
83
# File 'lib/parse/datatypes.rb', line 73

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



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

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



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

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

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

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  value.hash
end

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

Returns:

  • (Boolean)


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

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

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



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

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

#to_json(*a) ⇒ Object



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

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