class Handlebars::Helpers::Inflection::PluralizeByNumber
Pluralize
By Number: uses both a word and number to decide if the plural or singular form should be used.
Public Instance Methods
handlebars_helper()
click to toggle source
# File lib/handlebars/helpers/inflection/pluralize_by_number.rb, line 50 def handlebars_helper proc do |_context, value, count, format| # Handle optional: format format = nil if value.is_a?(V8::Object) wrapper(parse(value, count, format)) end end
parse(value, count, format)
click to toggle source
Parse will Pluralize
By Number: uses both a word and number to decide if the plural or singular form should be used.
@example
puts PluralizeByNumber.new.parse('category', '3', 'number_word') 3 categories
@example
puts PluralizeByNumber.new.parse('category', '3', 'word' ) categories puts PluralizeByNumber.new.parse('category', '1' ) category
@param [String] value - value to pluralize @param [Integer] count - count used to determine pluralization @param [String] format - (Optional) what format should output be. :word, :number_word @return [String] value and number are used to calculate plural/singular form
# File lib/handlebars/helpers/inflection/pluralize_by_number.rb, line 36 def parse(value, count, format) return '' if value.nil? count = count.to_i if count.is_a? String format = :word if format.nil? case format.to_sym when :number_word, :number_and_word "#{count} #{value.pluralize(count)}" else # aka :word value.pluralize(count) end end