Class: Jacoat::Document::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/jacoat/document/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/jacoat/document/error.rb', line 4

def code
  @code
end

#detailObject

Returns the value of attribute detail.



4
5
6
# File 'lib/jacoat/document/error.rb', line 4

def detail
  @detail
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/jacoat/document/error.rb', line 4

def id
  @id
end

Returns the value of attribute links.



4
5
6
# File 'lib/jacoat/document/error.rb', line 4

def links
  @links
end

#metaObject

Returns the value of attribute meta.



4
5
6
# File 'lib/jacoat/document/error.rb', line 4

def meta
  @meta
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/jacoat/document/error.rb', line 4

def status
  @status
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/jacoat/document/error.rb', line 4

def title
  @title
end

Class Method Details

.from_jsonapi(arguments) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/jacoat/document/error.rb', line 5

def self.from_jsonapi(arguments)
  error = Error.new
  error.id = arguments[:id]
  error.links = Link.from_jsonapi(arguments[:links]) if arguments.has_key?(:links)
  %w{ status code title detail }.each do |type|
    error.instance_variable_set("@#{type}", arguments[type.to_sym]) if arguments.has_key?(type.to_sym)
  end
  error.meta = Meta.from_jsonapi(arguments[:meta]) if arguments.has_key?(:meta)
  error
end

Instance Method Details

#to_hashObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jacoat/document/error.rb', line 16

def to_hash
  hash = {}
  hash[:id] = @id if @id
  hash[:links] = @links.to_hash if @links
  %w{ status code title detail }.each do |type|
    if self.instance_variable_defined?("@#{type}".to_sym)
      hash[type.to_sym] = instance_variable_get("@#{type}".to_sym)
    end
  end
  hash[:meta] = @meta.to_hash if @meta
  hash
end