Class: Jacoat::Document::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = {}) ⇒ Error

Returns a new instance of Error.



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

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



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

def detail
  @detail
end

#idObject (readonly)

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 (readonly)

Returns the value of attribute meta.



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

def meta
  @meta
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#to_hashObject



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

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