Class: BrowserOfBabel::Randomizer
- Inherits:
-
Object
- Object
- BrowserOfBabel::Randomizer
- Defined in:
- lib/browser_of_babel/randomizer.rb
Overview
Gets you to random places in Library of Babel.
Constant Summary collapse
- MAX_HEX =
("z" * 3260).to_i(36)
Instance Method Summary collapse
-
#hex ⇒ Hex
Get a random hex.
-
#hex_identifier ⇒ String
Get a random hex indetifier.
-
#initialize(random: ::Random.new) ⇒ Randomizer
constructor
A new instance of Randomizer.
-
#page ⇒ Page
Get a random page in a random volume and so on.
-
#page_identifier ⇒ Integer
Get a random page identifier.
-
#shelf ⇒ Shelf
Get a random shelf on a random wall in a random hex.
-
#shelf_identifier ⇒ Integer
Get a random shelf identifier.
-
#volume ⇒ Volume
Get a random volume on a random shelf and so on.
-
#volume_identifier ⇒ Integer
Get a random volume identifier.
-
#wall ⇒ Wall
Get a random wall in a random hex.
-
#wall_identifier ⇒ Integer
Get a random wall identifier.
Constructor Details
#initialize(random: ::Random.new) ⇒ Randomizer
Returns a new instance of Randomizer.
10 11 12 13 |
# File 'lib/browser_of_babel/randomizer.rb', line 10 def initialize(random: ::Random.new) @random = random @locator = Locator.new end |
Instance Method Details
#hex ⇒ Hex
Get a random hex.
23 24 25 |
# File 'lib/browser_of_babel/randomizer.rb', line 23 def hex @locator.from_identifiers(hex_identifier) # : Hex end |
#hex_identifier ⇒ String
Get a random hex indetifier.
17 18 19 |
# File 'lib/browser_of_babel/randomizer.rb', line 17 def hex_identifier @random.rand(MAX_HEX).to_s(36) end |
#page ⇒ Page
Get a random page in a random volume and so on.
75 76 77 78 79 |
# File 'lib/browser_of_babel/randomizer.rb', line 75 def page @locator.from_identifiers( hex_identifier, wall_identifier, shelf_identifier, volume_identifier, page_identifier ) # : Page end |
#page_identifier ⇒ Integer
Get a random page identifier.
69 70 71 |
# File 'lib/browser_of_babel/randomizer.rb', line 69 def page_identifier @random.rand(1..410) end |
#shelf ⇒ Shelf
Get a random shelf on a random wall in a random hex.
47 48 49 50 51 |
# File 'lib/browser_of_babel/randomizer.rb', line 47 def shelf @locator.from_identifiers( hex_identifier, wall_identifier, shelf_identifier ) # : Shelf end |
#shelf_identifier ⇒ Integer
Get a random shelf identifier.
41 42 43 |
# File 'lib/browser_of_babel/randomizer.rb', line 41 def shelf_identifier @random.rand(1..5) end |
#volume ⇒ Volume
Get a random volume on a random shelf and so on.
61 62 63 64 65 |
# File 'lib/browser_of_babel/randomizer.rb', line 61 def volume @locator.from_identifiers( hex_identifier, wall_identifier, shelf_identifier, volume_identifier ) # : Volume end |
#volume_identifier ⇒ Integer
Get a random volume identifier.
55 56 57 |
# File 'lib/browser_of_babel/randomizer.rb', line 55 def volume_identifier @random.rand(1..32) end |
#wall ⇒ Wall
Get a random wall in a random hex.
35 36 37 |
# File 'lib/browser_of_babel/randomizer.rb', line 35 def wall @locator.from_identifiers(hex_identifier, wall_identifier) # : Wall end |
#wall_identifier ⇒ Integer
Get a random wall identifier.
29 30 31 |
# File 'lib/browser_of_babel/randomizer.rb', line 29 def wall_identifier @random.rand(1..4) end |