Class: MobilePronto::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/mobilepronto/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, error = nil) ⇒ Result

Returns a new instance of Result.



8
9
10
11
# File 'lib/mobilepronto/result.rb', line 8

def initialize(code, error = nil)
  @code  = ["X01", "X02", :ok].include?(code) ? code : code.to_i
  @error = error
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/mobilepronto/result.rb', line 20

def method_missing(method, *args, &block)
  if block_given? && !(code = /on_([0-9]*)/.match(method)).nil?
    self.on(code[1].to_i, &block)
  else
    super(method, *args, &block)
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/mobilepronto/result.rb', line 5

def code
  @code
end

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/mobilepronto/result.rb', line 6

def error
  @error
end

Instance Method Details

#on(*args) ⇒ Object



13
14
15
16
17
18
# File 'lib/mobilepronto/result.rb', line 13

def on(*args)
  if block_given? and
     args.any? { |i| i.kind_of?(Range) ? i.include?(code) : i == code }
    yield
  end
end