Class: ReturnStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/erichmond-ruby-agi/return_status.rb

Overview

every method of this class would return string or boolean

methods of command class usually return ReturnStatus object

Instance Method Summary collapse

Constructor Details

#initialize(command, message) ⇒ ReturnStatus



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/erichmond-ruby-agi/return_status.rb', line 29

def initialize(command, message)
  @command = command.chomp
  @message = message
  @result = nil
  @digit = nil
  @digits = nil
  @return_code = nil
  @command_error = false

  if message.nil?
    @messsage = "No responses !!"
  else
    str = @message.split(' ')
    @return_code = str[0]
    if @return_code == '200'
      @result = str[1].split('=')[1]
    end
  end
end

Instance Method Details

#command_error?Boolean



79
80
81
# File 'lib/erichmond-ruby-agi/return_status.rb', line 79

def command_error?
  return (result.nil? or (not (@return_code == '200')))
end

#digitObject



60
61
62
63
64
65
66
# File 'lib/erichmond-ruby-agi/return_status.rb', line 60

def digit
  if (@result == '0')
    return nil
  else
    return @result.to_i.chr
  end
end

#digitsObject



69
70
71
# File 'lib/erichmond-ruby-agi/return_status.rb', line 69

def digits
  return @result.to_s
end

#messageObject



74
75
76
# File 'lib/erichmond-ruby-agi/return_status.rb', line 74

def message
  return @message.to_s
end

#resultObject



55
56
57
# File 'lib/erichmond-ruby-agi/return_status.rb', line 55

def result
  return @result.to_s
end

#timeout?Boolean



84
85
86
87
88
89
90
91
# File 'lib/erichmond-ruby-agi/return_status.rb', line 84

def timeout?
  rgx = Regexp.new(/\(timeout\)/)
  if rgx.match(@message)
    return true
  else
    return false
  end
end

#to_sObject



50
51
52
# File 'lib/erichmond-ruby-agi/return_status.rb', line 50

def to_s
  return @command.to_s + ' >> ' + @message.to_s
end