Class: Pinterest::Entity
- Inherits:
-
Object
- Object
- Pinterest::Entity
- Defined in:
- lib/pinterest/models/entity.rb
Overview
Base class for entity objects.
Class Method Summary collapse
-
.parse_timestamp(timestamp) ⇒ DateTime
Parses a timestamps.
Instance Method Summary collapse
-
#as_json(fields, options = {}) ⇒ Hash
Serialize the object as a Hash that can be serialized as JSON.
-
#initialize(data) ⇒ Pinterest::Board
constructor
Creates a new object.
Constructor Details
#initialize(data) ⇒ Pinterest::Board
Creates a new object.
22 23 24 25 26 |
# File 'lib/pinterest/models/entity.rb', line 22 def initialize(data) data.each do |field, value| send("#{field}=", value) if respond_to?(field) end end |
Class Method Details
.parse_timestamp(timestamp) ⇒ DateTime
Parses a timestamps.
13 14 15 16 |
# File 'lib/pinterest/models/entity.rb', line 13 def self.() return nil if ! || .empty? DateTime.parse( + "+00:00") end |
Instance Method Details
#as_json(fields, options = {}) ⇒ Hash
Serialize the object as a Hash that can be serialized as JSON.
32 33 34 35 36 37 38 39 40 |
# File 'lib/pinterest/models/entity.rb', line 32 def as_json(fields, = {}) fields.reduce({}) do |accu, field| value = send(field) value = value.as_json() if value.respond_to?(:as_json) accu[field.to_sym] = value accu end end |