Sha256: a535c0172149fef370ef6b213e6e38a3c69b1792c5f3c6d6c3305b21a7a449db

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

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

5 entries across 5 versions & 1 rubygems

Version Path
win-0.1.27 lib/win/extensions.rb
win-0.1.26 lib/win/extensions.rb
win-0.1.22 lib/win/extensions.rb
win-0.1.18 lib/win/extensions.rb
win-0.1.16 lib/win/extensions.rb