Module: NArrayExtensions

Defined in:
lib/narray_extensions.rb

Instance Method Summary collapse

Instance Method Details

#pretty_string(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/narray_extensions.rb', line 6

def pretty_string(opts={})
  { :col_header   => nil,
    :row_header   => nil }.merge!(opts)

  ("%-3s" % "#") + opts[:col_header].inject("") { |s, a| s + ("%7s" % a) } + "\n" +
    self.to_a.inject("%-3s" % opts[:row_header]) { |s, v|
    if v.is_a? Float
      s + ("%7.2f" % v)
    else
      s + ("%7d" % v)
    end
  }
end