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



37
38
39
40
41
42
43
# File 'lib/applitools/utils/utils.rb', line 37

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



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

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

#extract_options!(array) ⇒ Object



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

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

#symbolize_keys(hash) ⇒ Object



45
46
47
48
49
# File 'lib/applitools/utils/utils.rb', line 45

def symbolize_keys(hash)
  hash.each_with_object({}) do |(k, v), memo|
    memo[k.to_sym] = v
  end
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



29
30
31
# File 'lib/applitools/utils/utils.rb', line 29

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

#wrap(object) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/applitools/utils/utils.rb', line 19

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