class Mendel::Visualizers::ASCII
Attributes
point_width[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/mendel/visualizers/ascii.rb, line 8 def initialize(*args) super @point_width = 8 end
Public Instance Methods
axis_label_for(list_item)
click to toggle source
# File lib/mendel/visualizers/ascii.rb, line 32 def axis_label_for(list_item) fix_point_width(list_item.to_s) end
fix_point_width(string)
click to toggle source
# File lib/mendel/visualizers/ascii.rb, line 45 def fix_point_width(string) string[0...point_width].rjust(point_width, ' ') end
grid_point_for(status, score=nil)
click to toggle source
# File lib/mendel/visualizers/ascii.rb, line 36 def grid_point_for(status, score=nil) case status when :unscored then fix_point_width('') when :scored then fix_point_width(score.to_s).green when :returned then fix_point_width(score.to_s).blue else raise UnknownPointType, status.inspect end end
output()
click to toggle source
# File lib/mendel/visualizers/ascii.rb, line 13 def output horizontal_space = ' ' output_lines = [] grid.each_with_index do |line, y| x_label = axis_label_for(list1[y]) line_string = x_label points_on_line = line.each_with_index.map { |column, x| grid_point_for(*grid[y][x]) } line_string.concat(points_on_line.join(horizontal_space)) output_lines.unshift(line_string) end y_labels = list2.map {|item| axis_label_for(item) } footer_line = "#{fix_point_width('')}#{y_labels.join(horizontal_space)}" output_lines = output_lines.join("\n\n\n") output_lines.concat("\n#{footer_line}\n") end