Sha256: 9a46bd1a61c6ac95c55401ac345aa31a7fc5ca2243cb2c8a7414c0d1b2ad3b78

Contents?: true

Size: 1.11 KB

Versions: 29

Compression:

Stored size: 1.11 KB

Contents

#
# = bio/shell/object.rb - Object extension for the BioRuby shell
#
# Copyright::   Copyright (C) 2006
#               Nobuya Tanaka <t@chemruby.org>,
#               Toshiaki Katayama <k@bioruby.org>
# License::     The Ruby License
#
# $Id: object.rb,v 1.3 2007/04/05 23:35:41 trevor Exp $
#

require 'pp'
require 'cgi'
require 'yaml'

### Object extention

class Object
  # Couldn't work for Fixnum (Marshal)
  attr_accessor :memo

  def output(format = :yaml)
    case format
    when :yaml
      self.to_yaml
    when :html
      format_html
    when :inspect
      format_pp
    when :png
      # *TODO*
    when :svg
      # *TODO*
    when :graph
      # *TODO* (Gruff, RSRuby etc.)
    else
      #self.inspect.to_s.fold(80)
      self.to_s
    end
  end

  private

  def format_html
    "<pre>#{CGI.escapeHTML(format_pp)}</pre>"
  end

  def format_pp
    str = ""
    PP.pp(self, str)
    return str
  end

end

class Hash

  private

  def format_html
    html = ""
    html += "<table>"
    @data.each do |k, v|
      html += "<tr><td>#{k}</td><td>#{v}</td></tr>"
    end
    html += "</table>"
    return html
  end

end

Version data entries

29 entries across 29 versions & 6 rubygems

Version Path
bio-shell-1.0.1 lib/bio/shell/object.rb
bio-shell-1.0.0 lib/bio/shell/object.rb
bio-1.5.2 lib/bio/shell/object.rb
bio-shell-0.0.0 lib/bio/shell/object.rb
bio-1.5.1 lib/bio/shell/object.rb
bio-1.5.0 lib/bio/shell/object.rb
bioruby-bio-1.2.9.9001 lib/bio/shell/object.rb
bioruby-bio-1.2.9.9501 lib/bio/shell/object.rb
bioruby-bio-1.3.0.5000 lib/bio/shell/object.rb
bioruby-bio-1.3.0.9901 lib/bio/shell/object.rb
bioruby-bio-1.3.0 lib/bio/shell/object.rb
bioruby-bio-1.3.1.5000 lib/bio/shell/object.rb
jandot-bio-1.2.1 lib/bio/shell/object.rb
ngoto-bio-1.2.9.9001 lib/bio/shell/object.rb
ngoto-bio-1.2.9.9501 lib/bio/shell/object.rb
ngoto-bio-1.3.0.5000 lib/bio/shell/object.rb
ngoto-bio-1.3.0 lib/bio/shell/object.rb
ngoto-bio-1.3.1.5000 lib/bio/shell/object.rb
wwood-bioruby-1.2.11 lib/bio/shell/object.rb
bio-1.4.3.0001 lib/bio/shell/object.rb