Module: StringUtility
Constant Summary collapse
- STRING_VALS =
('A'..'F').to_a.freeze
- INT_VALS =
(0..9).to_a.freeze
- COMBINED_VALS =
(STRING_VALS + INT_VALS).freeze
Class Method Summary collapse
-
.random_color_six ⇒ String
Gets a random six-digit hexadecimal web color string.
-
.random_color_three ⇒ String
Gets a random three-digit hexadecimal web color string.
-
.random_line(path) ⇒ String
Gets a random line in a file.
Instance Method Summary collapse
- #random_color(limit) ⇒ Object private
Class Method Details
.random_color_six ⇒ String
Gets a random six-digit hexadecimal web color string.
76 77 78 |
# File 'lib/string_utility.rb', line 76 def self.random_color_six random_color(6) end |
.random_color_three ⇒ String
Gets a random three-digit hexadecimal web color string.
70 71 72 |
# File 'lib/string_utility.rb', line 70 def self.random_color_three random_color(3) end |
.random_line(path) ⇒ String
Gets a random line in a file. This will include newlines and similar characters, so you may want to chomp the result.
63 64 65 66 |
# File 'lib/string_utility.rb', line 63 def self.random_line(path) lines = File.readlines(path) lines[rand(lines.count)] end |
Instance Method Details
#random_color(limit) ⇒ Object (private)
86 87 88 89 90 91 92 |
# File 'lib/string_utility.rb', line 86 def random_color(limit) str = '#' limit.times do str << COMBINED_VALS.sample.to_s end str end |