Module: Algerb::Util

Included in:
File, Files, FilesBuilder, Generator
Defined in:
lib/algerb/util.rb

Instance Method Summary collapse

Instance Method Details

#file_to_class(file) ⇒ Object



2
3
4
# File 'lib/algerb/util.rb', line 2

def file_to_class(file)
  remove_ext(file).split('_').map {|word| word.capitalize }.join('')
end

#indentation(code, level) ⇒ Object



6
7
8
# File 'lib/algerb/util.rb', line 6

def indentation(code, level)
  code.split("\n").map {|line| ' ' * level + line + "\n" }.join('')
end

#remove_dir(path) ⇒ Object



10
11
12
# File 'lib/algerb/util.rb', line 10

def remove_dir(path)
  path.sub(%r{^([a-z0-9\_]*/)*}, '')
end

#remove_ext(path) ⇒ Object



14
15
16
# File 'lib/algerb/util.rb', line 14

def remove_ext(path)
  path.sub(/\.rb$/, '')
end

#split_dir_and_file(path) ⇒ Object



18
19
20
# File 'lib/algerb/util.rb', line 18

def split_dir_and_file(path)
  path.scan(%r{^(?:(.*)/)?([^/]+)$})[0]
end

#split_path_as_head_and_tail(path) ⇒ Object



22
23
24
# File 'lib/algerb/util.rb', line 22

def split_path_as_head_and_tail(path)
  path.split('/', 2)
end