Module: VimSdk::VmodlHelper

Defined in:
lib/ruby_vim_sdk/vmodl_helper.rb

Constant Summary collapse

UNDERSCORE_EXCEPTIONS =
{
  "numCPUs" => "num_cpus",
  "importVApp" => "import_vapp"
}

Class Method Summary collapse

Class Method Details

.camelize(word) ⇒ Object

Borrowed mostly from activesupport



8
9
10
# File 'lib/ruby_vim_sdk/vmodl_helper.rb', line 8

def camelize(word)
  word.gsub(/(?:^|_)(.)/) { $1.upcase }
end

.underscore(word) ⇒ Object

Borrowed mostly from activesupport



13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_vim_sdk/vmodl_helper.rb', line 13

def underscore(word)
  exception = UNDERSCORE_EXCEPTIONS[word]
  return exception if exception

  word = word.dup
  word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.downcase!
  word
end

.vmodl_property_to_ruby(name) ⇒ Object



28
29
30
# File 'lib/ruby_vim_sdk/vmodl_helper.rb', line 28

def vmodl_property_to_ruby(name)
  underscore(name)
end

.vmodl_type_to_ruby(name) ⇒ Object



24
25
26
# File 'lib/ruby_vim_sdk/vmodl_helper.rb', line 24

def vmodl_type_to_ruby(name)
  name.split(".").collect { |part| camelize(part) }.join(".")
end