Class: Blufin::Arrays
- Inherits:
-
Object
- Object
- Blufin::Arrays
- Defined in:
- lib/core/arrays.rb
Class Method Summary collapse
-
.array_has_duplicate(array, ignore_case = false) ⇒ Object
Checks if an array has duplicates.
-
.convert_line_array_to_string(array_of_lines) ⇒ Object
Converts an Array of lines to a string (for easier gsub replacement).
-
.convert_string_to_line_array(string) ⇒ Object
Converts a string to an Array of lines to a string.
Class Method Details
.array_has_duplicate(array, ignore_case = false) ⇒ Object
Checks if an array has duplicates.
7 8 9 10 11 12 13 14 |
# File 'lib/core/arrays.rb', line 7 def self.array_has_duplicate(array, ignore_case = false) raise RuntimeError, "Expected Array, but got #{array.class}" unless array.is_a?(Array) array = array.dup if ignore_case array.map! { |name| name.downcase } end !(array.uniq.length == array.length) end |
.convert_line_array_to_string(array_of_lines) ⇒ Object
Converts an Array of lines to a string (for easier gsub replacement).
18 19 20 21 22 23 24 25 26 |
# File 'lib/core/arrays.rb', line 18 def self.convert_line_array_to_string(array_of_lines) raise RuntimeError, "Expected Array of lines, instead got: #{array_of_lines.class}" unless array_of_lines.is_a?(Array) string = '' array_of_lines.each_with_index do |line, idx| newline_or_not = (idx == (array_of_lines.length - 1)) ? '' : "\n" string += "#{line}#{newline_or_not}" end string end |
.convert_string_to_line_array(string) ⇒ Object
Converts a string to an Array of lines to a string.
30 31 32 33 34 35 |
# File 'lib/core/arrays.rb', line 30 def self.convert_string_to_line_array(string) raise RuntimeError, "Expected String, instead got: #{string.class}" unless string.is_a?(String) array_of_lines = [] string.split("\n").each { |line| array_of_lines << line.gsub("\n", '') } array_of_lines end |