Module: Applitools::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/applitools/utils/utils.rb,
lib/applitools/utils/image_utils.rb,
lib/applitools/utils/eyes_selenium_utils.rb,
lib/applitools/utils/image_delta_compressor.rb

Defined Under Namespace

Modules: EyesSeleniumUtils, ImageDeltaCompressor, ImageUtils

Constant Summary collapse

RESAMPLE_INCREMENTALLY_FRACTION =
2

Instance Method Summary collapse

Instance Method Details

#boolean_value(value) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/applitools/utils/utils.rb', line 42

def boolean_value(value)
  if value
    true
  else
    false
  end
end

#camelcase(str) ⇒ Object



14
15
16
17
# File 'lib/applitools/utils/utils.rb', line 14

def camelcase(str)
  tokens = str.split('_')
  uncapitalize(tokens.shift) + tokens.map(&:capitalize).join
end

#camelcase_hash_keys(hash) ⇒ Object



38
39
40
# File 'lib/applitools/utils/utils.rb', line 38

def camelcase_hash_keys(hash)
  convert_hash_keys(hash, :camelcase)
end

#extract_options!(array) ⇒ Object



56
57
58
59
# File 'lib/applitools/utils/utils.rb', line 56

def extract_options!(array)
  return array.pop if array.last.instance_of? Hash
  {}
end

#symbolize_keys(hash) ⇒ Object



50
51
52
53
54
# File 'lib/applitools/utils/utils.rb', line 50

def symbolize_keys(hash)
  hash.each_with_object({}) do |(k, v), memo|
    memo[k.to_sym] = v
  end
end

#to_method_name(str) ⇒ Object



19
20
21
22
# File 'lib/applitools/utils/utils.rb', line 19

def to_method_name(str)
  str = str.to_s if !str.is_a?(String) && str.respond_to?(:to_s)
  underscore(str).gsub(%r{\/}, '__')
end

#uncapitalize(str) ⇒ Object



10
11
12
# File 'lib/applitools/utils/utils.rb', line 10

def uncapitalize(str)
  str[0, 1].downcase + str[1..-1]
end

#underscore(str) ⇒ Object



6
7
8
# File 'lib/applitools/utils/utils.rb', line 6

def underscore(str)
  str.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
end

#underscore_hash_keys(hash) ⇒ Object



34
35
36
# File 'lib/applitools/utils/utils.rb', line 34

def underscore_hash_keys(hash)
  convert_hash_keys(hash, :underscore)
end

#wrap(object) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/applitools/utils/utils.rb', line 24

def wrap(object)
  if object.nil?
    []
  elsif object.respond_to?(:to_ary)
    object.to_ary || [object]
  else
    [object]
  end
end