module RollString

This encapsulates the Roll class' string generation methods.

Public Instance Methods

to_s(no_spaces = false) click to toggle source
# File lib/dicebag/roll_string.rb, line 6
def to_s(no_spaces = false)
  @parts = []

  to_s_tree

  str = @parts.join ' '

  no_spaces ? str.tr(' ', '') : str
end

Private Instance Methods

_op_value(op, value) click to toggle source
# File lib/dicebag/roll_string.rb, line 48
def _op_value(op, value)
  "#{op}#{value}"
end
to_s_add(value) click to toggle source
# File lib/dicebag/roll_string.rb, line 32
def to_s_add(value)
  _op_value '+', value
end
to_s_div(value) click to toggle source
# File lib/dicebag/roll_string.rb, line 44
def to_s_div(value)
  _op_value '/', value
end
to_s_label(value) click to toggle source
# File lib/dicebag/roll_string.rb, line 24
def to_s_label(value)
  value.to_s
end
to_s_mul(value) click to toggle source
# File lib/dicebag/roll_string.rb, line 40
def to_s_mul(value)
  _op_value '*', value
end
to_s_start(value) click to toggle source
# File lib/dicebag/roll_string.rb, line 28
def to_s_start(value)
  value.to_s
end
to_s_sub(value) click to toggle source
# File lib/dicebag/roll_string.rb, line 36
def to_s_sub(value)
  _op_value '-', value
end
to_s_tree() click to toggle source
# File lib/dicebag/roll_string.rb, line 18
def to_s_tree
  tree.each do |op, value|
    @parts.push send("to_s_#{op}", value)
  end
end