Sha256: c2e001e03569c4407048c31bd2a7aaf83875ef9bf023187a8c8d947fab801ac2

Contents?: true

Size: 831 Bytes

Versions: 9

Compression:

Stored size: 831 Bytes

Contents

module Watir
  class Util
    class << self

      # @example
      #   Watir::Util.demodulize("Watir::Span") # => "Span"
      def demodulize(str)
        str.gsub(/^.*::/, '')
      end

      # @example
      #   Watir::Util.underscore("FooBar") # => "foo_bar"
      def underscore(str)
        str.gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
      end

      # @example
      #   Watir::Util.singularize("Checkboxes") # => "Checkbox"
      #   Watir::Util.singularize("Bodies") # => "Body"
      #   Watir::Util.singularize("Buttons") # => "Button"
      def singularize(str)
        case str.downcase
        when "checkboxes"
          str.chop.chop
        when "bodies"
          str.chop.chop.chop + "y"
        else
          str.chop
        end
      end
    end    
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
watir-classic-4.3.0 lib/watir-classic/util.rb
watir-classic-4.2.0 lib/watir-classic/util.rb
watir-classic-4.1.0 lib/watir-classic/util.rb
watir-classic-4.0.1 lib/watir-classic/util.rb
watir-classic-4.0.0 lib/watir-classic/util.rb
watir-classic-3.7.0 lib/watir-classic/util.rb
watir-classic-3.6.0 lib/watir-classic/util.rb
watir-classic-3.5.0 lib/watir-classic/util.rb
watir-classic-3.4.0 lib/watir-classic/util.rb