Class: Watir::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-classic/util.rb

Class Method Summary collapse

Class Method Details

.demodulize(str) ⇒ Object

Examples:

Watir::Util.demodulize("Watir::Span") # => "Span"


7
8
9
# File 'lib/watir-classic/util.rb', line 7

def demodulize(str)
  str.gsub(/^.*::/, '')
end

.singularize(str) ⇒ Object

Examples:

Watir::Util.singularize("Checkboxes") # => "Checkbox"
Watir::Util.singularize("Bodies") # => "Body"
Watir::Util.singularize("Buttons") # => "Button"


21
22
23
24
25
26
27
28
29
30
# File 'lib/watir-classic/util.rb', line 21

def singularize(str)
  case str.downcase
  when "checkboxes"
    str.chop.chop
  when "bodies"
    str.chop.chop.chop + "y"
  else
    str.chop
  end
end

.underscore(str) ⇒ Object

Examples:

Watir::Util.underscore("FooBar") # => "foo_bar"


13
14
15
# File 'lib/watir-classic/util.rb', line 13

def underscore(str)
  str.gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
end