Class: Mendel::Visualizers::ASCII

Inherits:
Base
  • Object
show all
Defined in:
lib/mendel/visualizers/ascii.rb

Instance Attribute Summary

Attributes inherited from Base

#combiner, #grid, #list1, #list2

Instance Method Summary collapse

Methods inherited from Base

max_list_length, #update

Constructor Details

#initialize(*args) ⇒ ASCII

Returns a new instance of ASCII.



8
9
10
11
# File 'lib/mendel/visualizers/ascii.rb', line 8

def initialize(*args)
  super
  @point_width = 8
end

Instance Method Details

#axis_label_for(list_item) ⇒ Object



32
33
34
# 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) ⇒ Object



45
46
47
# 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) ⇒ Object



36
37
38
39
40
41
42
43
# 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

#outputObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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