Module: Franc

Included in:
String
Defined in:
lib/franc.rb,
lib/franc/version.rb

Overview

This runs a bash command for Titus Wormer’s franc. More info on franc can be found here: github.com/wooorm/franc

If franc is not installed globally on computer system, this will not work.

Constant Summary collapse

VERSION =
'0.0.3'

Instance Method Summary collapse

Instance Method Details

#ask_installObject

Asks if user would like to install franc.



14
15
16
17
18
19
# File 'lib/franc.rb', line 14

def ask_install
  puts 'Looks like franc has not been installed yet.'
  puts 'Would you like to install it now? (y/n)'
  answer = gets.chomp!
  install(answer)
end

#install(str) ⇒ Object

If user presses RETURN or gives anything besides no, franc is installed.



22
23
24
25
26
27
28
# File 'lib/franc.rb', line 22

def install(str)
  return if %w(no n).include?(str)
  puts 'installing...'
  `npm install -g franc`
  puts "\nnpm successfully installed franc."
  true # Just for looks really, better than returning nil.
end

#language(str = self) ⇒ Object



6
7
8
9
10
11
# File 'lib/franc.rb', line 6

def language(str = self)
  formstr = str.gsub(/\W\s/, ' ') # Replace special chars with a space.
  `franc #{formstr}`.strip!
rescue Errno::ENOENT
  ask_install
end