Module: Space2underscore
- Defined in:
- lib/space2underscore.rb,
lib/space2underscore/version.rb
Constant Summary collapse
- VERSION =
'0.2.1'
Class Method Summary collapse
- .convert(argv) ⇒ Object
- .copy_cmd ⇒ Object
- .create_new_branch(underscore_include_sentence) ⇒ Object
- .execute_command(command) ⇒ Object
- .generate_command(underscore_include_sentence) ⇒ Object
Class Method Details
.convert(argv) ⇒ Object
5 6 7 |
# File 'lib/space2underscore.rb', line 5 def convert(argv) argv.length == 1 ? argv[0].strip.gsub(/\s/, '_') : argv.join('_') end |
.copy_cmd ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/space2underscore.rb', line 17 def copy_cmd if system("type pbcopy > /dev/null 2>&1") "pbcopy" elsif system("type xsel > /dev/null 2>&1") "xsel --input --clipboard" elsif system("type xclip > /dev/null 2>&1") "xclip" end end |
.create_new_branch(underscore_include_sentence) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/space2underscore.rb', line 27 def create_new_branch(underscore_include_sentence) print "Do you create the new branch? [y/Y]" flag = $stdin.gets.chomp if !!(flag =~ /^y(es)?$/i) || flag == '' system "git checkout -b #{underscore_include_sentence}" "Branch has been created." else execute_command(generate_command(underscore_include_sentence)) "Branch name has been copied to clipboard." end end |
.execute_command(command) ⇒ Object
13 14 15 |
# File 'lib/space2underscore.rb', line 13 def execute_command(command) system command end |
.generate_command(underscore_include_sentence) ⇒ Object
9 10 11 |
# File 'lib/space2underscore.rb', line 9 def generate_command(underscore_include_sentence) "echo #{underscore_include_sentence} | ruby -pe 'chomp' | #{copy_cmd}" end |