Module: StringHelpers
- Defined in:
- lib/railsbricks/string_helpers.rb
Class Method Summary collapse
-
.convert_to_app_name(value) ⇒ Object
convert a string to a valid Rails app name.
-
.new_line(lines = 1) ⇒ Object
simply displays empty lines.
-
.sanitize(value) ⇒ Object
replaces special characters with ‘_’.
-
.wputs(text, highlight = :none) ⇒ Object
Wraps output text at 79 columns.
Class Method Details
.convert_to_app_name(value) ⇒ Object
convert a string to a valid Rails app name
16 17 18 19 20 21 22 |
# File 'lib/railsbricks/string_helpers.rb', line 16 def self.convert_to_app_name(value) if value.scan(/\_|\-/).size > 0 value.split(/\_|\-/).map(&:capitalize).join else value.slice(0,1).capitalize + value.slice(1..-1) end end |
.new_line(lines = 1) ⇒ Object
simply displays empty lines
11 12 13 |
# File 'lib/railsbricks/string_helpers.rb', line 11 def self.new_line(lines=1) lines.times { puts } end |
.sanitize(value) ⇒ Object
replaces special characters with ‘_’
6 7 8 |
# File 'lib/railsbricks/string_helpers.rb', line 6 def self.sanitize(value) value.tr('^A-Za-z0-9', '_') end |
.wputs(text, highlight = :none) ⇒ Object
Wraps output text at 79 columns. Outputs in green if highlight = :info / red if :error / blue if :help
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/railsbricks/string_helpers.rb', line 26 def self.wputs(text, highlight = :none) text = text.gsub(/\n/, ' ').gsub(/(.{1,#{79}})(\s+|$)/, "\\1\n").strip if highlight == :info puts UiHelpers.colorize(text, UiHelpers::GREEN) elsif highlight == :error puts UiHelpers.colorize(text, UiHelpers::RED) elsif highlight == :help puts UiHelpers.colorize(text, UiHelpers::BLUE) else puts text end end |