Class: CW::Alphabet
- Inherits:
-
Object
- Object
- CW::Alphabet
- Defined in:
- lib/cw/alphabet.rb
Overview
class Alphabet provides alphabet generation functionality
Instance Method Summary collapse
-
#alphabet ⇒ Object
alphabet() Returns alphabet as string == Parameters: none.
-
#exclude_letters ⇒ Object
exclude_letters() exclude letters if :exclude option defined == Parameters: none.
-
#generate ⇒ Object
generate() generate alphabet with options acted upon == Returns: alphabet or filtered alphabet.
-
#include_letters ⇒ Object
include_letters() include letters if :include option defined == Parameters: none.
-
#initialize(options = {}) ⇒ Alphabet
constructor
- initialize class Alphabet == Parameters: options
-
An optional hash containg options: :reverse - reverse alphabet :shuffle - shuffle alphabet :include - include only these letters of the alphabet :exclude - exclude these letters from the alphabet.
-
#reverse_alphabet_maybe ⇒ Object
reverse_alphabet_maybe() reverse letters if reverse option set == Parameters: none.
-
#shuffle_alphabet_maybe ⇒ Object
shuffle_alphabet_maybe() shuffle alphabet if :shuffle option defined don’t shuffle if in test environment == Parameters: none.
Constructor Details
#initialize(options = {}) ⇒ Alphabet
initialize class Alphabet
Parameters:
- options
-
An optional hash containg options:
:reverse - reverse alphabet :shuffle - shuffle alphabet :include - include only these letters of the alphabet :exclude - exclude these letters from the alphabet
18 19 20 |
# File 'lib/cw/alphabet.rb', line 18 def initialize( = {}) = end |
Instance Method Details
#alphabet ⇒ Object
alphabet() Returns alphabet as string
Parameters:
none
27 28 29 |
# File 'lib/cw/alphabet.rb', line 27 def alphabet 'abcdefghijklmnopqrstuvwxyz' end |
#exclude_letters ⇒ Object
exclude_letters() exclude letters if :exclude option defined
Parameters:
none
68 69 70 71 72 |
# File 'lib/cw/alphabet.rb', line 68 def exclude_letters if [:exclude] @letters.tr!([:exclude],'') end end |
#generate ⇒ Object
generate() generate alphabet with options acted upon
Returns:
alphabet or filtered alphabet
79 80 81 82 83 84 85 86 |
# File 'lib/cw/alphabet.rb', line 79 def generate @letters = alphabet include_letters exclude_letters shuffle_alphabet_maybe reverse_alphabet_maybe @letters.split('').join(' ') end |
#include_letters ⇒ Object
include_letters() include letters if :include option defined
Parameters:
none
57 58 59 60 61 |
# File 'lib/cw/alphabet.rb', line 57 def include_letters if [:include] @letters = [:include] end end |
#reverse_alphabet_maybe ⇒ Object
reverse_alphabet_maybe() reverse letters if reverse option set
Parameters:
none
36 37 38 |
# File 'lib/cw/alphabet.rb', line 36 def reverse_alphabet_maybe @letters.reverse! if [:reverse] end |
#shuffle_alphabet_maybe ⇒ Object
shuffle_alphabet_maybe() shuffle alphabet if :shuffle option defined don’t shuffle if in test environment
Parameters:
none
46 47 48 49 50 |
# File 'lib/cw/alphabet.rb', line 46 def shuffle_alphabet_maybe unless(ENV["CW_ENV"] == "test") @letters = @letters.split('').shuffle.join if [:shuffle] end end |