class Bio::PSORT::CGIDriver

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

Attributes

args[RW]

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

report[R]

CGI output raw text

Public Class Methods

new(host = '', path = '') click to toggle source

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"))
# 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

Public Instance Methods

exec(query) click to toggle source

Executes a CGI “query'' and returns aReport

# 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

Private Instance Methods

args_join(hash, delim = '&') click to toggle source

Returns CGI argument text in String (key=value&) from a Hash ({key=>value}).

# File lib/bio/appl/psort.rb, line 141
def args_join(hash, delim = '&')
  tmp = []
  hash.each do |key, val|
    tmp << CGI.escape(key.to_s) + '=' + CGI.escape(val.to_s)
  end
  return tmp.join(delim)  # not ';' but '&' in the psort cgi script.
end
erase_html_tags(str) click to toggle source

Erases HTML tags

# File lib/bio/appl/psort.rb, line 136
def erase_html_tags(str)
  return str.gsub(/<\S.*?>/, '')
end
make_args(args_hash) click to toggle source

Bio::CGIDriver#make_args. An API skelton.

# File lib/bio/appl/psort.rb, line 126
def make_args(args_hash)
  # The routin should be provided in the inherited class
end
parse_report(result_body) click to toggle source

Bio::CGIDriver#parse_report. An API skelton.

# File lib/bio/appl/psort.rb, line 131
def parse_report(result_body)
  # The routin should be provided in the inherited class
end