Class: BasicForgery
Constant Summary collapse
- HEX_DIGITS =
%w{0 1 2 3 4 5 6 7 8 9 a b c d e f}
- UPPER_ALPHA =
('A'..'Z').to_a
- LOWER_ALPHA =
('a'..'z').to_a
- NUMERIC =
('0'..'9').to_a
- SPECIAL_CHARACTERS =
%w{! ' @ # $ % ^ & * ( ) _ + - = [ ] { } ; : " , . / ?}
- BOOLEAN =
[true, false]
Class Method Summary collapse
- .boolean ⇒ Object
- .color ⇒ Object
- .encrypt(password = "password", salt = Time.now.to_s) ⇒ Object
- .frequency ⇒ Object
- .hex_color ⇒ Object
- .number(options = {}) ⇒ Object
- .password(options = {}) ⇒ Object
- .short_hex_color ⇒ Object
- .text(options = {}) ⇒ Object
Methods inherited from Forgery
Class Method Details
.boolean ⇒ Object
25 26 27 |
# File 'lib/forgeries/basic_forgery.rb', line 25 def self.boolean BOOLEAN.random end |
.color ⇒ Object
29 30 31 |
# File 'lib/forgeries/basic_forgery.rb', line 29 def self.color dictionaries[:colors].random end |
.encrypt(password = "password", salt = Time.now.to_s) ⇒ Object
21 22 23 |
# File 'lib/forgeries/basic_forgery.rb', line 21 def self.encrypt(password="password", salt=Time.now.to_s) Digest::SHA1.hexdigest("--#{salt}--#{password}--") end |
.frequency ⇒ Object
68 69 70 |
# File 'lib/forgeries/basic_forgery.rb', line 68 def self.frequency dictionaries[:frequencies].random end |
.hex_color ⇒ Object
33 34 35 36 |
# File 'lib/forgeries/basic_forgery.rb', line 33 def self.hex_color hex_digits = (1..6).collect { HEX_DIGITS.random} "##{hex_digits.join}" end |
.number(options = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/forgeries/basic_forgery.rb', line 42 def self.number(={}) = {:at_least => 1, :at_most => 10}.merge() ([:at_least]..[:at_most]).random end |
.password(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/forgeries/basic_forgery.rb', line 11 def self.password(={}) = {:at_least => 6, :at_most => 12, :allow_lower => true, :allow_upper => true, :allow_numeric => true, :allow_special => false}.merge!() self.text() end |
.short_hex_color ⇒ Object
38 39 40 |
# File 'lib/forgeries/basic_forgery.rb', line 38 def self.short_hex_color hex_color[0,4] end |
.text(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/forgeries/basic_forgery.rb', line 49 def self.text(={}) = {:at_least => 10, :at_most => 15, :allow_lower => true, :allow_upper => true, :allow_numeric => true, :allow_special => false}.merge!() allowed_characters = [] allowed_characters += LOWER_ALPHA if [:allow_lower] allowed_characters += UPPER_ALPHA if [:allow_upper] allowed_characters += NUMERIC if [:allow_numeric] allowed_characters += SPECIAL_CHARACTERS if [:allow_special] length = ([:at_least]..[:at_most]).random allowed_characters.random_subset(length).join end |