Sha256: ab2d16039c93fec1e29ad99626055e128413fe927dbcf3acb58dcce39842175b

Contents?: true

Size: 1013 Bytes

Versions: 4

Compression:

Stored size: 1013 Bytes

Contents

class String
  # returns snake_case representation of string
  def snake_case
    gsub(/([a-z])([A-Z0-9])/, '\1_\2' ).downcase
  end

  # returns camel_case representation of string
  def camel_case
    if self.include? '_'
      self.split('_').map{|e| e.capitalize}.join
    else
      unless self =~ (/^[A-Z]/)
        self.capitalize
      else
        self
      end
    end
  end

  # converts string to 'wide char' (Windows Unicode) format
  def to_w
    (self+"\x00").encode('utf-16LE')
  end
  
  # converts one-char string into keyboard-scan 'Virtual key' code
  # only letters and numbers convertable so far, need to be extended
  def to_vkeys
    unless size == 1
      raise "Can't convert but a single character: #{self}"
    end
    ascii = upcase.unpack('C')[0]
    case self
      when 'a'..'z', '0'..'9', ' '
      [ascii]
      when 'A'..'Z'
      [0x10, ascii]    # Win.const_get(:VK_SHIFT) = 0x10 Bad coupling
    else
      raise "Can't convert unknown character: #{self}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
win-0.3.6 lib/win/extensions.rb
win-0.3.5 lib/win/extensions.rb
win-0.3.3 lib/win/extensions.rb
win-0.3.1 lib/win/extensions.rb