Module: NArrayExtensions

Defined in:
lib/narray_extensions.rb

Instance Method Summary collapse

Instance Method Details

#pretty_string(options = {}) ⇒ Object



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

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

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