class String

Adds a few extra methods to the standard String

Public Instance Methods

camel_case() click to toggle source
# File lib/screenplay/datatype-extensions.rb, line 143
def camel_case
        self.split('_').collect(&:capitalize).join
end
normalize() click to toggle source

Normalizes a string, remove diacritics (accents)

# File lib/screenplay/datatype-extensions.rb, line 116
def normalize
        tr(
                "ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž",
                "AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz")
end
numeric?() click to toggle source

Returns true if a string is numeric.

# File lib/screenplay/datatype-extensions.rb, line 106
def numeric?
        self.to_i.to_s == self
end
replace_vars(input) click to toggle source
# File lib/screenplay/datatype-extensions.rb, line 133
def replace_vars(input)
        result = self.dup
        result.replace_vars!(input)
        return result
end
replace_vars!(input, sep_char = '.') click to toggle source
# File lib/screenplay/datatype-extensions.rb, line 126
def replace_vars!(input, sep_char = '.')
        input = {} unless input.is_a?(Hash)
        self.gsub!(/\#({[\w#{Regexp.escape(sep_char)}]+})/) { | key |
                input.get_value_from_path(key.delete("{}#"))
        }
end
snake_case() click to toggle source
# File lib/screenplay/datatype-extensions.rb, line 139
def snake_case
        self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr('-', '_').downcase
end
strip_quotes() click to toggle source

Strips single or double quotes at the start and end of the given string.

# File lib/screenplay/datatype-extensions.rb, line 111
def strip_quotes
        gsub(/\A['"]+|['"]+\Z/, '')
end
truncate(max_length, ellipses = '...') click to toggle source
# File lib/screenplay/datatype-extensions.rb, line 122
def truncate(max_length, ellipses = '...')
        (self.length > max_length) ? self.to_s[0..max_length].gsub(/[^\w]\w+\s*$/, '...') : self.to_s
end