class DiceGraph
Public Class Methods
new(r, how_many, top_number_of_dice)
click to toggle source
# File lib/dicebag.rb, line 158 def initialize(r, how_many, top_number_of_dice) @data = generate_text_graph(r, how_many, top_number_of_dice) end
Public Instance Methods
generate_text_graph(r, how_many, top_number_of_dice)
click to toggle source
# File lib/dicebag.rb, line 166 def generate_text_graph(r, how_many, top_number_of_dice) raise "There are no statistical results to graph. Run :generate_results" unless r data = "Running #{how_many} times, taking the top #{top_number_of_dice}, the breakdown of results by value rolled are:" data << "\n" + ("◘" * 30) + "\n" r.sort.each do |total, count| percentage = (count.to_f/how_many.to_f) data << sprintf("%3d ", total) data << '(' data << sprintf("%5.2f", percentage * 100) data << "%) " dots = (percentage*500).to_i if dots > 100 data << '▃' * 80 data << "*(#{dots})" else data << '▃' * (percentage*500).to_i end data << "\n" end data end
graph()
click to toggle source
# File lib/dicebag.rb, line 162 def graph @data end