Sha256: 619dd439a1529c8fbfd4301dff0e4da2602eb28bb7135d216c919792f56036e0

Contents?: true

Size: 576 Bytes

Versions: 9

Compression:

Stored size: 576 Bytes

Contents

module ToPass::Converters
  class Swapcase
    class << self
      # alternate case of letter (not numbers)
      def swapcase(string)
        pwd = ""
        last_upcase = true

        string.each_char do |char|
          char = if char.between?("0", "9")
                   char
                 elsif last_upcase
                   last_upcase = false
                   char.downcase
                 else
                   last_upcase = true
                   char.upcase
                 end
          pwd << char
        end
        pwd
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
to_pass-1.0.1 data/to_pass/converters/swapcase.rb
to_pass-1.0.0 data/to_pass/converters/swapcase.rb
to_pass-0.9.0 data/to_pass/converters/swapcase.rb
to_pass-0.8.0 data/to_pass/converters/swapcase.rb
to_pass-0.7.0 data/to_pass/converters/swapcase.rb
to_pass-0.6.0 data/to_pass/converters/swapcase.rb
to_pass-0.5.2 lib/to_pass/converters/swapcase.rb
to_pass-0.5.0 lib/to_pass/converters/swapcase.rb
to_pass-0.4.0 lib/to_pass/converters/swapcase.rb