Class: Parse::Bytes

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

Overview

Bytes


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Bytes

Returns a new instance of Bytes.



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

def initialize(data)
  bytes = data["base64"]
  @value = Base64.decode64(bytes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



138
139
140
141
142
143
144
# File 'lib/parse/datatypes.rb', line 138

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.



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

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



134
135
136
# File 'lib/parse/datatypes.rb', line 134

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

#as_json(*a) ⇒ Object



150
151
152
153
154
155
# File 'lib/parse/datatypes.rb', line 150

def as_json(*a)
  {
      Protocol::KEY_TYPE => Protocol::TYPE_BYTES,
      "base64" => Base64.encode64(@value)
  }
end

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

Returns:

  • (Boolean)


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

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

#hashObject



130
131
132
# File 'lib/parse/datatypes.rb', line 130

def hash
  value.hash
end

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

Returns:

  • (Boolean)


146
147
148
# File 'lib/parse/datatypes.rb', line 146

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

#to_json(*a) ⇒ Object



157
158
159
# File 'lib/parse/datatypes.rb', line 157

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