Class: CharPool
- Inherits:
-
Object
- Object
- CharPool
- Defined in:
- lib/char_pool.rb,
lib/char_pool/version.rb
Constant Summary collapse
- VERSION =
"1.0.2"
Instance Method Summary collapse
- #index(string) ⇒ Object
- #index_at(number) ⇒ Object
-
#initialize(char_pool) ⇒ CharPool
constructor
A new instance of CharPool.
- #next ⇒ Object
- #print ⇒ Object
- #start(current = @char_pool.first) ⇒ Object
Constructor Details
#initialize(char_pool) ⇒ CharPool
Returns a new instance of CharPool.
4 5 6 7 8 9 |
# File 'lib/char_pool.rb', line 4 def initialize(char_pool) raise(ArgumentError, 'Pool should be array') unless char_pool.is_a?(Array) raise(ArgumentError, 'Pool cannot be empty') if char_pool.empty? @char_pool = char_pool.uniq.map &:to_s end |
Instance Method Details
#index(string) ⇒ Object
34 35 36 |
# File 'lib/char_pool.rb', line 34 def index(string) decode(string) end |
#index_at(number) ⇒ Object
29 30 31 32 |
# File 'lib/char_pool.rb', line 29 def index_at(number) encode(number).map{|i| @char_pool[i]} .join end |
#next ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/char_pool.rb', line 21 def next @current_index = 0 and return print if @current_index.nil? @current_index += 1 print end |
#print ⇒ Object
17 18 19 |
# File 'lib/char_pool.rb', line 17 def print index_at @current_index end |
#start(current = @char_pool.first) ⇒ Object
11 12 13 14 15 |
# File 'lib/char_pool.rb', line 11 def start(current = @char_pool.first) @current_index = index(current) current end |