Module: CharacterRanges
- Included in:
- RandomStringGenerator
- Defined in:
- lib/character_ranges.rb
Overview
CharacterRanges Module
CharacterRanges provides preset ranges for sets of ASCII characters for random password generation.
List of Ranges
upper_alphas
-
0x41..0x5a - A..Z
lower_alphas
-
0x61..0x7a - a..z
numerals
-
0x30..0x30 - 0..9
symbols_1
-
0x21..0x21 - !
symbols_2
-
0x23..0x26 - #..&
symbols_3
-
0x28..0x2f - (../
symbols_4
-
0x3a..0x40 - :..@
symbols_5
-
0x5b..0x5f - [.._
symbols_6
-
0x7b..0x7e - {..~
single_quotes
-
0x27..0x27 - ‘
double_quotes
-
0x22..0x22 - “
backtick
-
0x60..0x60 - ‘
Instance Method Summary collapse
-
#range(sym) ⇒ Object
Get a specific range.
-
#range_all ⇒ Object
All the ranges except the quote ranges (ie single, double, and backtick).
-
#range_all_except_quotes ⇒ Object
All the ranges except the quote ranges (ie single, double, and backtick).
-
#range_backtick ⇒ Object
The backtick ASCII ranges as a single-member Array.
-
#range_double_quotes ⇒ Object
The double quotes ASCII ranges as a single-member Array.
-
#range_lower_alphas ⇒ Object
The lower case alpha ASCII range as a single-member Array.
-
#range_numerals ⇒ Object
The numeral ASCII ranges as a single-member Array.
-
#range_single_quotes ⇒ Object
The single quotes ASCII ranges as a single-member Array.
-
#range_symbols ⇒ Object
The symbols ASCII ranges as a 6-member Array.
-
#range_upper_alphas ⇒ Object
The upper case alpha ASCII ranges as a single-member Array.
Instance Method Details
#range(sym) ⇒ Object
Get a specific range. See “List of Ranges” above.
Example:
CharacterRanges.range( :upper_alphas ) => 0x41..0x5a
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/character_ranges.rb', line 49 def range( sym ) case sym.to_sym when :upper_alphas 0x41..0x5a when :lower_alphas 0x61..0x7a when :numerals 0x30..0x39 when :symbols_1 0x21..0x21 when :symbols_2 0x23..0x26 when :symbols_3 0x28..0x2f when :symbols_4 0x3a..0x40 when :symbols_5 0x5b..0x5f when :symbols_6 0x7b..0x7e when :single_quotes 0x27..0x27 when :double_quotes 0x22..0x22 when :backtick 0x60..0x60 else raise ArgumentError, "#{sym.to_s} is an invalid range." end end |
#range_all ⇒ Object
All the ranges except the quote ranges (ie single, double, and backtick).
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/character_ranges.rb', line 171 def range_all [ range(:upper_alphas), range(:lower_alphas), range(:numerals), range(:symbols_1), range(:symbols_2), range(:symbols_3), range(:symbols_4), range(:symbols_5), range(:symbols_6), range(:single_quotes), range(:double_quotes), range(:backtick) ] end |
#range_all_except_quotes ⇒ Object
All the ranges except the quote ranges (ie single, double, and backtick).
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/character_ranges.rb', line 129 def range_all_except_quotes [ range(:upper_alphas), range(:lower_alphas), range(:numerals), range(:symbols_1), range(:symbols_2), range(:symbols_3), range(:symbols_4), range(:symbols_5), range(:symbols_6) ] end |
#range_backtick ⇒ Object
The backtick ASCII ranges as a single-member Array.
(0x60..0x60 - ‘)
164 165 166 |
# File 'lib/character_ranges.rb', line 164 def range_backtick [ range(:backtick) ] end |
#range_double_quotes ⇒ Object
The double quotes ASCII ranges as a single-member Array.
(0x22..0x22 - “)
155 156 157 |
# File 'lib/character_ranges.rb', line 155 def range_double_quotes [ range(:double_quotes) ] end |
#range_lower_alphas ⇒ Object
The lower case alpha ASCII range as a single-member Array.
(0x61..0x7a - a..z)
94 95 96 |
# File 'lib/character_ranges.rb', line 94 def range_lower_alphas [ range(:lower_alphas) ] end |
#range_numerals ⇒ Object
The numeral ASCII ranges as a single-member Array.
0x30..0x30 - 0..9
103 104 105 |
# File 'lib/character_ranges.rb', line 103 def range_numerals [ range(:numerals) ] end |
#range_single_quotes ⇒ Object
The single quotes ASCII ranges as a single-member Array.
(0x27..0x27 - ‘)
146 147 148 |
# File 'lib/character_ranges.rb', line 146 def range_single_quotes [ range(:single_quotes) ] end |
#range_symbols ⇒ Object
The symbols ASCII ranges as a 6-member Array.
symbols_1
-
0x21..0x21 - !
symbols_2
-
0x23..0x26 - #..&
symbols_3
-
0x28..0x2f - (../
symbols_4
-
0x3a..0x40 - :..@
symbols_5
-
0x5b..0x5f - [.._
symbols_6
-
0x7b..0x7e - {..~
117 118 119 120 121 122 123 124 |
# File 'lib/character_ranges.rb', line 117 def range_symbols [ range(:symbols_1), range(:symbols_2), range(:symbols_3), range(:symbols_4), range(:symbols_5), range(:symbols_6) ] end |
#range_upper_alphas ⇒ Object
The upper case alpha ASCII ranges as a single-member Array.
(0x41..0x5a - A..Z)
85 86 87 |
# File 'lib/character_ranges.rb', line 85 def range_upper_alphas [ range(:upper_alphas) ] end |