module Bio::Protparam::Remote

Constants

PROTPARAM_URL

Attributes

result[RW]

Public Class Methods

cast_method(type) click to toggle source
# File lib/bio/util/protparam.rb, line 378
def self.cast_method(type)
  case type.to_s
  when "Fixnum"
    ".to_i"
  when "Float"
    ".to_f"
  when "String"
    ""
  else
    ""
  end
end
extract_options(*args) click to toggle source
# File lib/bio/util/protparam.rb, line 391
def self.extract_options(*args)
  # label, class, regex
  # label, class, regex, lambda
  # label, lambda
  label, type, regex, block = [nil, nil, nil, nil]
  if args.size > 2
    label = args.shift
    type  = args.shift
    if args.size > 1
      regex, block = args
    elsif args.size > 0
      regex, block = if args.first.kind_of?(Regexp)
                       [args.first, nil]
                     elsif args.first.respond_to?(:call)
                       [nil, args.first]
                     end
    end
  end
  [label, type, regex, block]
end
rule(*args) click to toggle source
# File lib/bio/util/protparam.rb, line 412
    def self.rule(*args)
      (label, type, regex, block) = extract_options(*args)
      if regex && block
        self.class_eval <<-METHOD
        METHOD
      elsif regex && !block
        self.class_eval <<-METHOD
            def #{label}
              response = self.request
              matched  = %r/#{regex}/.match(response)
              if matched.size > 1
                matched[1]#{cast_method(type)}
              else
                nil
              end
            end
                METHOD
      elsif !regex && block
        wrapped_block = Proc.new {|*method_args|
          response = self.request
          method_args.unshift response
          block.call(method_args)
        }
        self.send(:define_method, label, &wrapped_block)
      else
        raise ArgumentError,
          "Invalid arguments.rule(:label, :type, :regex) or rule(:label, :type, :lambda)"
      end
    end

Public Instance Methods

fallback!() click to toggle source
# File lib/bio/util/protparam.rb, line 500
def fallback!
  self.class.class_eval do
    include Local
  end
end
request() click to toggle source
# File lib/bio/util/protparam.rb, line 492
def request
  @result ||= begin
                res = Net::HTTP.post_form(URI(PROTPARAM_URL),
                                          {'sequence' => @seq.to_s})
                res.body
              end
end
stable?() click to toggle source
# File lib/bio/util/protparam.rb, line 488
def stable?
  (stablity == 'stable')
end