Class: Doozer::Lib
Class Method Summary collapse
-
.classify(klass) ⇒ Object
Return a ClassName as string from an underscored string.
-
.pathify_first(s) ⇒ Object
Returns a one-level deep folder/file structure and preservers underscores for filename.
-
.underscore(s) ⇒ Object
Return an underscored string from a ClassName string.
Class Method Details
.classify(klass) ⇒ Object
Return a ClassName as string from an underscored string. example: input “example_class” > “ExampleClass”
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/doozer/lib.rb', line 6 def self.classify(klass) if klass.index('_') klass = klass.split('_') parts = [] klass = klass.each { | part | parts.push(part.capitalize) } klass = parts.join('') else klass = klass.capitalize end return klass end |
.pathify_first(s) ⇒ Object
Returns a one-level deep folder/file structure and preservers underscores for filename. example: input “folder_some_file_name” > “folder/some_file_name”
33 34 35 36 37 38 39 40 41 |
# File 'lib/doozer/lib.rb', line 33 def self.pathify_first(s) if s.index('_') parts = s.split('_') folder = parts[0] file = parts.slice(1, parts.length).join('_') s = "#{folder}/#{file}" end s end |
.underscore(s) ⇒ Object
Return an underscored string from a ClassName string. example: input “ExampleClass” > “example_class”
22 23 24 25 26 27 28 29 |
# File 'lib/doozer/lib.rb', line 22 def self.underscore(s) while true do m = /[A-Z]/.match(s) break if m.to_s == '' s.gsub!(/#{m.to_s}/,"_#{m.to_s.downcase}") end s.gsub(/^_/,'') # move the first underscore end |