Class: Parse::Increment

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

Overview

Increment and Decrement


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount) ⇒ Increment

Returns a new instance of Increment.



181
182
183
# File 'lib/parse/datatypes.rb', line 181

def initialize(amount)
  @amount = amount
end

Instance Attribute Details

#amountObject

‘{“score”: {“__op”: “Increment”, “amount”: 1 } }’



179
180
181
# File 'lib/parse/datatypes.rb', line 179

def amount
  @amount
end

Instance Method Details

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

Returns:

  • (Boolean)


185
186
187
188
# File 'lib/parse/datatypes.rb', line 185

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

#hashObject



192
193
194
# File 'lib/parse/datatypes.rb', line 192

def hash
  amount.hash
end

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



196
197
198
199
200
201
# File 'lib/parse/datatypes.rb', line 196

def to_h(*a)
  {
      Protocol::KEY_OP => Protocol::KEY_INCREMENT,
      Protocol::KEY_AMOUNT => @amount
  }
end

#to_json(*a) ⇒ Object



204
205
206
# File 'lib/parse/datatypes.rb', line 204

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