Module: Gemify

Extended by:
Gemify
Included in:
Gemify
Defined in:
lib/gemify.rb,
lib/gemify/version.rb

Constant Summary collapse

WARNINGS =
{}
VERSION =
'0.4.0'

Instance Method Summary collapse

Instance Method Details

#ask(attribute, value) ⇒ Object

Asks the user for a correct value of an attribute:

>> input! "correct\n"
>> ask("Hello", "world")
=> "correct"
>> last_output
=> "Hello:               world? "

If the user just presses ENTER, use the provided value:

>> input! "\n"
>> ask("Hello", "world")
=> "world"
>> last_output
=> "Hello:               world? "


19
20
21
22
23
24
# File 'lib/gemify.rb', line 19

def ask(attribute, value)
  col = "#{attribute}:".ljust(20)
  print "#{col} #{value}? "
  new_value = $stdin.gets.chomp
  new_value.empty? ? value : new_value
end

#clean_name(name) ⇒ Object

>> clean_name(“Hello Æwesome!”)

=> "Hellowesome"


48
49
50
# File 'lib/gemify.rb', line 48

def clean_name(name)
  name.gsub(/[^a-zA-Z0-9_-]/, '')
end

#n(str) ⇒ Object



83
84
85
# File 'lib/gemify.rb', line 83

def n(str)
  puts "[+] #{str}"
end

#name_to_namespace(name) ⇒ Object

Converts a project name into a namespace:

>> name_to_namespace('foo_bar-qux')
=> "FooBar::Qux"


56
57
58
# File 'lib/gemify.rb', line 56

def name_to_namespace(name)
  name.gsub(/_?([a-zA-Z0-9]+)/) { $1.capitalize }.gsub('-', '::')
end

#namespace_to_library(namespace) ⇒ Object

Converts a namespace to a library name:

>> namespace_to_library("FooBar::Qux")
=> "foo_bar/qux"
>> namespace_to_library("HTTParty")
=> "httparty"


66
67
68
69
70
# File 'lib/gemify.rb', line 66

def namespace_to_library(namespace)
  namespace.split("::").map do |part|
    part.scan(/([A-Z]+[a-z0-9]+)/).join('_').downcase
  end.join('/')
end

#w(type, str) ⇒ Object



74
75
76
77
# File 'lib/gemify.rb', line 74

def w(type, str)
  WARNINGS[type] = true
  puts "- #{str}"
end

#w?(type) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/gemify.rb', line 79

def w?(type)
  WARNINGS[type]
end

#yes(question) ⇒ Object

Asks a question which defaults to false.

>> input! "Y\n"
>> yes("Well?")
=> true
>> last_output
=> "[?] Well? (y/[N]) "

>> input! "\n"
>> yes("Well?")
=> false
>> last_output
=> "[?] Well? (y/[N]) "


39
40
41
42
# File 'lib/gemify.rb', line 39

def yes(question)
  print "[?] #{question} (y/[N]) "
  $stdin.gets[0,1].downcase == "y"
end