Class: Hash
- Inherits:
- Object
- Object
- Hash
- Defined in:
- lib/parse/model/file.rb,
lib/parse/model/object.rb
Overview
Adds extensions to Hash class.
Instance Method Summary collapse
- #parse_file? ⇒ Boolean
Determines if the hash contains Parse File json metadata fields.
- #parse_object ⇒ Parse::Object
Turns a Parse formatted JSON hash into a Parse-Stack class object, if one is found.
Instance Method Details
#parse_file? ⇒ Boolean
Determines if the hash contains Parse File json metadata fields. This is determined whether the key `__type` exists and is of type `__File` and whether the `name` field matches the File.basename of the `url` field.
208 209 210 211 212 213 | # File 'lib/parse/model/file.rb', line 208 def parse_file? url = self[Parse::File::FIELD_URL] name = self[Parse::File::FIELD_NAME] (count == 2 || self["__type"] == Parse::File.parse_class) && url.present? && name.present? && name == ::File.basename(url) end |
#parse_object ⇒ Parse::Object
Turns a Parse formatted JSON hash into a Parse-Stack class object, if one is found. This is equivalent to calling `Parse::Object.build` on the hash object itself, but allows for doing this in loops, such as `map` when using symbol to proc. However, you can also use the Array extension `Array#parse_objects` for doing that more safely.
536 537 538 | # File 'lib/parse/model/object.rb', line 536 def parse_object Parse::Object.build(self) end |