Module: DataDuck::Util
- Defined in:
- lib/dataduck/util.rb
Class Method Summary collapse
- .camelcase_to_underscore(str) ⇒ Object
- .ensure_path_exists!(full_path) ⇒ Object
- .underscore_to_camelcase(str) ⇒ Object
Class Method Details
.camelcase_to_underscore(str) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/dataduck/util.rb', line 17 def Util.camelcase_to_underscore(str) str.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') .gsub(/([a-z\d])([A-Z])/,'\1_\2') .tr("-", "_") .downcase end |
.ensure_path_exists!(full_path) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/dataduck/util.rb', line 5 def Util.ensure_path_exists!(full_path) split_paths = full_path.split('/') just_file_path = split_paths.pop directory_path = split_paths.join('/') FileUtils.mkdir_p(directory_path) FileUtils.touch("#{ directory_path }/#{ just_file_path }") end |
.underscore_to_camelcase(str) ⇒ Object
13 14 15 |
# File 'lib/dataduck/util.rb', line 13 def Util.underscore_to_camelcase(str) str.split('_').map{ |chunk| chunk.capitalize }.join end |