Class: Handlebars::Helpers::Inflection::Ordinal

Inherits:
BaseHelper
  • Object
show all
Defined in:
lib/handlebars/helpers/inflection/ordinal.rb

Overview

Ordinal: The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th

Instance Method Summary collapse

Methods inherited from BaseHelper

#parse_json, #struct_to_hash, #tokenizer, #wrapper

Instance Method Details

#handlebars_helperObject



50
51
52
53
54
# File 'lib/handlebars/helpers/inflection/ordinal.rb', line 50

def handlebars_helper
  proc do |_context, value|
    wrapper(parse(value))
  end
end

#parse(value) ⇒ String

Parse will Ordinal: The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th

Examples:


puts Ordinal.new.parse('1')

st

puts Ordinal.new.parse('2')

nd

puts Ordinal.new.parse('3')

rd

puts Ordinal.new.parse('4')

th

Parameters:

  • value (String)
    • numeric value

Returns:

  • (String)

    ordinal suffix that would be required for a number



42
43
44
45
46
47
48
# File 'lib/handlebars/helpers/inflection/ordinal.rb', line 42

def parse(value)
  return '' if value.nil?

  value = value.to_i if value.is_a? String

  value.ordinal
end