Class: Bio::Sequence::Format::FormatterBase

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/sequence/format.rb

Overview

Formatter base class. Any formatter class should inherit this class.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequence, options = {}) ⇒ FormatterBase

creates a new formatter object for output



100
101
102
103
# File 'lib/bio/sequence/format.rb', line 100

def initialize(sequence, options = {})
  @sequence = sequence
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object (private)

any unknown methods are delegated to the sequence object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/bio/sequence/format.rb', line 108

def method_missing(sym, *args, &block) #:nodoc:
  begin
    @sequence.__send__(sym, *args, &block)
  rescue NoMethodError => evar
    lineno = __LINE__ - 2
    file = __FILE__
    bt_here = [ "#{file}:#{lineno}:in \`__send__\'",
                "#{file}:#{lineno}:in \`method_missing\'"
              ]
    if bt_here == evar.backtrace[0, 2] then
      bt = evar.backtrace[2..-1]
      evar = evar.class.new("undefined method \`#{sym.to_s}\' for #{self.inspect}")
      evar.set_backtrace(bt)
    end
    raise(evar)
  end
end

Class Method Details

.output(sequence, options = {}) ⇒ Object

Returns a formatterd string of the given sequence


Arguments:

  • (required) sequence: Bio::Sequence object

  • (optional) options: a Hash object

Returns

String object



80
81
82
# File 'lib/bio/sequence/format.rb', line 80

def self.output(sequence, options = {})
  self.new(sequence, options).output
end

Instance Method Details

#outputObject

generates output data


Returns

String object

Raises:

  • (NotImplementedError)


95
96
97
# File 'lib/bio/sequence/format.rb', line 95

def output
  raise NotImplementedError, 'should be implemented in subclass'
end