Class: ASCIIPlot
- Inherits:
-
Object
- Object
- ASCIIPlot
- Defined in:
- lib/ascii_plot.rb
Constant Summary collapse
- DOT =
'.'- EMPTY =
' '- X_AXIS =
'-'- Y_AXIS =
'|'
Instance Method Summary collapse
-
#initialize(x_start, x_end, y_start, y_end) ⇒ ASCIIPlot
constructor
A new instance of ASCIIPlot.
- #plot(point_list) ⇒ Object
Constructor Details
#initialize(x_start, x_end, y_start, y_end) ⇒ ASCIIPlot
Returns a new instance of ASCIIPlot.
8 9 10 11 12 13 |
# File 'lib/ascii_plot.rb', line 8 def initialize(x_start, x_end, y_start, y_end) @x_start = x_start @x_end = x_end @y_start = y_start @y_end = y_end end |
Instance Method Details
#plot(point_list) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ascii_plot.rb', line 15 def plot(point_list) output = '' @y_end.downto(@y_start).each do |y| (@x_start..@x_end).each do |x| if point_list.include?([x,y]) output << DOT elsif x == 0 output << Y_AXIS elsif y == 0 output << X_AXIS else output << EMPTY end end output << "\n" end output end |