Module: PureValidator::Humanize
- Defined in:
- lib/pure_validator/core_extensions/humanize.rb
Class Method Summary collapse
-
.humanize(value, options = {}) ⇒ Object
poor mans humanize…
Class Method Details
.humanize(value, options = {}) ⇒ Object
poor mans humanize… (to not depend on inflector) puts humanize “hello_there”, format: :class
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pure_validator/core_extensions/humanize.rb', line 5 def self.humanize(value, = {}) [:format] = :sentence if .empty? values = if value.include? '_' value.split('_') else [value] end values.each { |v| v.downcase! } if [:format] == :allcaps values.each do |value| value.capitalize! end if .empty? [:seperator] = " " end return values.join " " end if [:format] == :class values.each do |value| value.capitalize! end return values.join "" end if [:format] == :sentence values[0].capitalize! return values.join " " end if [:format] == :nocaps return values.join " " end end |