Class: TextChart::Designer
- Inherits:
-
Object
- Object
- TextChart::Designer
- Defined in:
- lib/text_chart/designer.rb
Instance Method Summary collapse
- #draw_axis ⇒ Array<String>
- #draw_bars ⇒ Array<String>
- #draw_header ⇒ Array<String>
-
#initialize(text_chart, size_calc) ⇒ Designer
constructor
A new instance of Designer.
- #paint ⇒ Array<String>
Constructor Details
#initialize(text_chart, size_calc) ⇒ Designer
Returns a new instance of Designer.
5 6 7 8 9 |
# File 'lib/text_chart/designer.rb', line 5 def initialize(text_chart, size_calc) @text_chart = text_chart @size_calc = size_calc @chart_canvas = build_empty_chart end |
Instance Method Details
#draw_axis ⇒ Array<String>
22 23 24 25 26 27 28 |
# File 'lib/text_chart/designer.rb', line 22 def draw_axis draw_x_axis draw_y_axis draw_references @chart_canvas end |
#draw_bars ⇒ Array<String>
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/text_chart/designer.rb', line 31 def last_line_index = @chart_canvas.size - 1 zero_line = last_line_index - @text_chart.size_config(:x_axis_height) chart_line = 0 ref_width = @size_calc.calculate_reference_width y_axis_width = @text_chart.size_config(:y_axis_width) = @text_chart.size_config(:bar_margin) = "###" = @text_chart.size_config(:bar_width) = = = 0 = .each do |height| = if == 0 ref_width + + y_axis_width else # + 1 because bar_end put us on the bar last column + 1 + end # - 1 because bar_start already put us on the bar first column = + - 1 chart_line = zero_line = height - 1 height.times do |t| @chart_canvas[chart_line][..] = chart_line -= 1 unless t == end end @chart_canvas end |
#draw_header ⇒ Array<String>
12 13 14 15 16 17 18 19 |
# File 'lib/text_chart/designer.rb', line 12 def draw_header header = [] header << "#{@text_chart.title}\n" header << "#{@text_chart.subtitle}\n" header << "\n" @chart_canvas.prepend(*header) end |
#paint ⇒ Array<String>
67 68 69 70 71 72 73 74 75 |
# File 'lib/text_chart/designer.rb', line 67 def paint @chart_canvas.map do |row| next if row.gsub!(@text_chart.title, colorize(@text_chart.title, :bold)) row.gsub!(/-?\d/) { colorize($&, :cyan) } row.gsub!(/#+/) { colorize($&, :blue) } end @chart_canvas end |