Class: Bio::PSORT::CGIDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/appl/psort.rb

Overview

Generic CGI client class

A generic CGI client class for Bio::PSORT::* classes. The class provides an interface for CGI argument processing and output report parsing.

Example

class NewClient < CGIDriver
  def initialize(host, path)
    super(host, path)
  end
end
private
def make_args(query)
  # ...
end
def parse_report(output)
  # ...
end

Direct Known Subclasses

PSORT1::Remote, PSORT2::Remote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = '', path = '') ⇒ CGIDriver

Sets remote host name and cgi path or uri.

Examples

CGIDriver.new("localhost", "/cgi-bin/psort_www.pl")

CGIDriver.new("http://localhost/cgi-bin/psort_www.pl")

CGIDriver.new(URI.parse("http://localhost/cgi-bin/psort_www.pl"))


94
95
96
97
98
99
100
101
102
103
104
# File 'lib/bio/appl/psort.rb', line 94

def initialize(host = '', path = '')
  case host.to_s
  when /^http:/
    uri = host.to_s
  else
    uri = 'http://' + host + '/' + path
  end
  @uri = URI.parse(uri)
  @args = {}
  @report = ''
end

Instance Attribute Details

#argsObject

CGI query argument in Hash (=> value, …).



78
79
80
# File 'lib/bio/appl/psort.rb', line 78

def args
  @args
end

#reportObject (readonly)

CGI output raw text



81
82
83
# File 'lib/bio/appl/psort.rb', line 81

def report
  @report
end

Instance Method Details

#exec(query) ⇒ Object

Executes a CGI “query'' and returns aReport



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/bio/appl/psort.rb', line 108

def exec(query)
  data = make_args(query)  

  begin
    result = nil
    Bio::Command.start_http(@uri.host) {|http|
      result = http.post(@uri.path, data)
    }
    @report = result.body
    output = parse_report(@report)
  end

  return output
end