Class: Meshchat::Ui::Command::Roll
- Defined in:
- lib/meshchat/ui/command/roll.rb
Constant Summary collapse
- REGEX =
/(\d+)d(\d+)(([+-])(\d+))?/
Constants inherited from Base
Base::ADD, Base::ALL_CHAT_LOCK, Base::BIND, Base::CHAT, Base::CONFIG, Base::DISPLAY, Base::EMOTE, Base::EXIT, Base::EXPORT, Base::HELP, Base::IDENTITY, Base::IMPORT, Base::IRB, Base::OFFLINE, Base::ONLINE, Base::PING, Base::PING_ALL, Base::QUIT, Base::REMOVE, Base::RM, Base::ROLL, Base::SEND_DISCONNECT, Base::SERVER, Base::SERVERS, Base::SET, Base::SHARE, Base::WHISPER_LOCK, Base::WHO
Instance Attribute Summary
Attributes inherited from Base
#_input, #_input_factory, #_message_dispatcher, #_message_factory
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input, message_dispatcher, message_factory, input_factory) ⇒ Roll
constructor
A new instance of Roll.
- #show_myself(message) ⇒ Object
- #type ⇒ Object
Methods inherited from Chat
Methods inherited from Base
Constructor Details
#initialize(input, message_dispatcher, message_factory, input_factory) ⇒ Roll
Returns a new instance of Roll.
12 13 14 15 16 17 18 19 |
# File 'lib/meshchat/ui/command/roll.rb', line 12 def initialize(input, , , input_factory) super # input, X, Y, +Z, Z _, num, size, modifier, _operator, number = REGEX.match(input).to_a result = Array.new(num.to_i) { rand(size.to_i) + 1 }.inject(:+) + modifier.to_i @_input = "rolls #{num}d#{size}#{modifier != 0 ? modifier : ''} and gets #{result}" end |
Class Method Details
.description ⇒ Object
8 9 10 |
# File 'lib/meshchat/ui/command/roll.rb', line 8 def self.description 'rolls a die in the XdY+Z format' end |