class Ella::NameFormatter
Ruby and rubyist convention demand that the project name be formatted in different ways depending on context. This class helps prevent repetition of name formatting. Thousands of Edabit exercises have prepared me for this, my finest hour. I am currently assuming that no one will be initializing in or using camelCase, as that format seems to have very little use in the Ruby community.
Attributes
snake_case[R]
Public Class Methods
new(name)
click to toggle source
# File lib/ella/name_formatter.rb, line 14 def initialize(name) Ella.abort('Project name must be a valid string.') if name.nil? || name.empty? # If the project name is given in Pascal Case, save as snake case. @snake_case = name =~ /^[A-Z]/ ? name.gsub(/([A-Z])/, '_\1')[1..-1].downcase : name end
Public Instance Methods
file_name()
click to toggle source
# File lib/ella/name_formatter.rb, line 20 def file_name "#{@snake_case}.rb" end
human()
click to toggle source
# File lib/ella/name_formatter.rb, line 28 def human @snake_case.split('_').map(&:capitalize).join(' ') end
pascal_case()
click to toggle source
# File lib/ella/name_formatter.rb, line 24 def pascal_case @snake_case.split('_').map(&:capitalize).join('') end