class MinceMigrator::Migrations::Name
Attributes
value[R]
Public Class Methods
new(value)
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 6 def initialize(value) self.value = value if value @errors = [] end
Public Instance Methods
capitalized_phrase(val)
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 20 def capitalized_phrase(val) val.split(' ').each_with_index.map do |word, i| i == 0 ? word.capitalize : word.downcase end.join(" ") end
filename()
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 11 def filename @filename ||= "#{value.downcase.gsub(" ", "_")}.rb" end
normalized_string(val)
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 26 def normalized_string(val) val = val.gsub(/[-_]/, ' ') # convert dashes and underscores to spaces pattern = /(^[0-9]|[^a-zA-Z0-9\s])/ # only allow letters and numbers, but do not allow numbers at the beginning val.gsub(pattern, '') end
reasons_for_failure()
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 38 def reasons_for_failure @errors.join(" ") end
valid?()
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 32 def valid? @errors = [] validate_value @errors.empty? end
validate_value()
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 42 def validate_value @errors << "Name is invalid, it must start with a character from A-Z or a-z" if value.nil? || value == '' end
value=(val)
click to toggle source
# File lib/mince_migrator/migrations/name.rb, line 15 def value=(val) normalized_string = normalized_string(val) @value = capitalized_phrase(normalized_string) end