class Blufin::Arrays
Public Class Methods
array_has_duplicate(array, ignore_case = false)
click to toggle source
Checks if an array has duplicates. @return boolean
# 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)
click to toggle source
Converts an Array of lines to a string (for easier gsub replacement). @return String
# 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)
click to toggle source
Converts a string to an Array of lines to a string. @return String
# 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