Class: Lita::Handlers::Random
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Random
- Defined in:
- lib/lita/handlers/random.rb
Overview
Generator of random numbers and strings for the Lita chat bot.
Instance Method Summary collapse
- #route_random(response) ⇒ Object
- #route_random_base64(response) ⇒ Object
- #route_random_base64_n(response) ⇒ Object
- #route_random_float_from_to(response) ⇒ Object
- #route_random_float_to(response) ⇒ Object
- #route_random_from_to(response) ⇒ Object
- #route_random_hex(response) ⇒ Object
- #route_random_hex_n(response) ⇒ Object
- #route_random_to(response) ⇒ Object
- #route_random_uuid(response) ⇒ Object
Instance Method Details
#route_random(response) ⇒ Object
14 15 16 |
# File 'lib/lita/handlers/random.rb', line 14 def route_random(response) response.reply(::Random.rand.to_s) end |
#route_random_base64(response) ⇒ Object
50 51 52 |
# File 'lib/lita/handlers/random.rb', line 50 def route_random_base64(response) response.reply(SecureRandom.base64) end |
#route_random_base64_n(response) ⇒ Object
56 57 58 59 |
# File 'lib/lita/handlers/random.rb', line 56 def route_random_base64_n(response) n = response.matches[0][0].to_i response.reply(SecureRandom.base64(n)) end |
#route_random_float_from_to(response) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/lita/handlers/random.rb', line 42 def route_random_float_from_to(response) matches = response.matches[0] from = matches[0].to_f to = matches[1].to_f response.reply(::Random.rand(from...to).to_s) end |
#route_random_float_to(response) ⇒ Object
25 26 27 28 |
# File 'lib/lita/handlers/random.rb', line 25 def route_random_float_to(response) to = response.matches[0][1].to_f response.reply(::Random.rand(to).to_s) end |
#route_random_from_to(response) ⇒ Object
32 33 34 35 36 |
# File 'lib/lita/handlers/random.rb', line 32 def route_random_from_to(response) from = response.matches[0][1].to_i to = response.matches[0][2].to_i response.reply(::Random.rand(from...to).to_s) end |
#route_random_hex(response) ⇒ Object
62 63 64 |
# File 'lib/lita/handlers/random.rb', line 62 def route_random_hex(response) response.reply(SecureRandom.hex) end |
#route_random_hex_n(response) ⇒ Object
68 69 70 71 |
# File 'lib/lita/handlers/random.rb', line 68 def route_random_hex_n(response) n = response.matches[0][0].to_i response.reply(SecureRandom.hex(n)) end |
#route_random_to(response) ⇒ Object
19 20 21 22 |
# File 'lib/lita/handlers/random.rb', line 19 def route_random_to(response) to = response.matches[0][1].to_i response.reply(::Random.rand(to).to_s) end |
#route_random_uuid(response) ⇒ Object
74 75 76 |
# File 'lib/lita/handlers/random.rb', line 74 def route_random_uuid(response) response.reply(SecureRandom.uuid) end |