Class: Opencellid::Error

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

Overview

Models an error object received from the server

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, info) ⇒ Error

Returns a new instance of Error.

Parameters:

  • code (Integer)

    the code identifying this error

  • info (String)

    a human readable explanation of the error



13
14
15
16
# File 'lib/opencellid/error.rb', line 13

def initialize(code, info)
  @info = info
  @code = code
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



9
10
11
# File 'lib/opencellid/error.rb', line 9

def code
  @code
end

#infoObject

Returns the value of attribute info.



9
10
11
# File 'lib/opencellid/error.rb', line 9

def info
  @info
end

Class Method Details

.from_element(element) ⇒ Error

Parses the given XML element extracting the information into the corresponding Error object

Parameters:

  • element (REXML::Element)

    an XML element containing the error

Returns:

  • (Error)

    the error object created by parsing the XML element

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
# File 'lib/opencellid/error.rb', line 21

def self.from_element(element)
  return nil unless element
  raise ArgumentError, 'element must be of type XEXML::Element' unless element.is_a? REXML::Element
  raise ArgumentError, 'element must be an <err>' unless element.name == 'err'
  attrs = element.attributes
  return Error.new(::Opencellid.to_i_or_nil(attrs['code']),attrs['info'])
end