Class: JSONAPI::Ruby::Deserializer::Resource

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/jsonapi-ruby-deserializer/resource.rb

Instance Attribute Summary collapse

Attributes included from Parser

#to_h

Instance Method Summary collapse

Methods included from Parser

#parse!

Constructor Details

#initialize(data) ⇒ Resource

Returns a new instance of Resource.



12
13
14
15
16
17
18
19
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 12

def initialize(data)
  @id = data['id']
  @type = data['type']
  @attributes = parse_attributes!(data['attributes'])
  @links = parse_links!(data['links'])
  @meta = parse_meta!(data['meta'])
  @relationships = parse_relationships!(data['relationships'])
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



10
11
12
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 10

def attributes
  @attributes
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 10

def id
  @id
end

Returns the value of attribute links.



10
11
12
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 10

def links
  @links
end

#metaObject

Returns the value of attribute meta.



10
11
12
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 10

def meta
  @meta
end

#relationshipsObject

Returns the value of attribute relationships.



10
11
12
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 10

def relationships
  @relationships
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 10

def type
  @type
end

Instance Method Details

#parse_attributes!(data) ⇒ Object



39
40
41
42
43
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 39

def parse_attributes!(data)
  return if data.nil? || data.empty?

  Attributes.new(data)
end

#parse_links!(data) ⇒ Object



27
28
29
30
31
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 27

def parse_links!(data)
  return if data.nil? || data.empty?

  Links.new(data)
end

#parse_meta!(data) ⇒ Object



33
34
35
36
37
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 33

def parse_meta!(data)
  return if data.nil? || data.empty?

  Meta.new(data)
end

#parse_relationships!(data) ⇒ Object



21
22
23
24
25
# File 'lib/jsonapi-ruby-deserializer/resource.rb', line 21

def parse_relationships!(data)
  return if data.nil? || data.empty?

  Relationships.new(data)
end