Class: CXML::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/cxml/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Status

Initialize a new Status instance



9
10
11
12
13
14
15
16
17
# File 'lib/cxml/status.rb', line 9

def initialize(data={})
  data = CXML.parse(data) if data.kind_of?(String)

  if data.kind_of?(Hash) && !data.empty?
    @code     = data['code'].to_i
    @text     = data['text']
    @xml_lang = data['xml:lang']
  end
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/cxml/status.rb', line 3

def code
  @code
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/cxml/status.rb', line 4

def text
  @text
end

#xml_langObject

Returns the value of attribute xml_lang.



5
6
7
# File 'lib/cxml/status.rb', line 5

def xml_lang
  @xml_lang
end

Instance Method Details

#failure?Boolean

Check if status is failure

Returns:

  • (Boolean)


27
28
29
# File 'lib/cxml/status.rb', line 27

def failure?
  !success?
end

#render(node) ⇒ Object



31
32
33
# File 'lib/cxml/status.rb', line 31

def render(node)
  node.Status(:code => @code, :text => @text)
end

#success?Boolean

Check if status is success

Returns:

  • (Boolean)


21
22
23
# File 'lib/cxml/status.rb', line 21

def success?
  [200, 201, 204, 280, 281].include?(code)
end