Class: Rubyspark::Spark

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyspark.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = []) ⇒ Spark

a new instance of RubySpark::Spark


7
8
9
10
11
# File 'lib/rubyspark.rb', line 7

def initialize data = []
  @data = []
  data.cycle(1) { |x| @data.push(x.to_f) }
  graphit
end

Instance Method Details

#compute(x, distance) ⇒ Fixnum

Compute x's location in relation to the max


18
19
20
# File 'lib/rubyspark.rb', line 18

def compute x, distance
  (x / distance).round - 1
end

#graphitString

Graphs data, takes data and maps it against flat map of ticks


24
25
26
27
28
# File 'lib/rubyspark.rb', line 24

def graphit
  ticks = %w(▁ ▂ ▃ ▄ ▅ ▆ ▇)
  distance = @data.max.to_f / ticks.size
  puts @data.map { |x| compute(x, distance) <= 0 ? ticks[0] : ticks[compute(x, distance)] }.join('')
end