Class: Rubyspark::Spark
- Inherits:
-
Object
- Object
- Rubyspark::Spark
- Defined in:
- lib/rubyspark.rb
Instance Method Summary collapse
- #graphit ⇒ Object
-
#initialize(data = []) ⇒ Spark
constructor
A new instance of Spark.
Constructor Details
#initialize(data = []) ⇒ Spark
Returns a new instance of Spark.
5 6 7 8 9 |
# File 'lib/rubyspark.rb', line 5 def initialize(data=[]) @data = [] data.cycle(1) {|x| @data.push(x.to_i)} graphit end |
Instance Method Details
#graphit ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rubyspark.rb', line 11 def graphit ticks=%w[▁ ▂ ▃ ▄ ▅ ▆ ▇] distance = @data.compact.max.to_f / ticks.size graph = '' @data.each do |x| tick = (x/distance).round - 1 if tick <= 0 graph << ticks[0] else graph << ticks[tick] end end puts graph end |