Class: Handlebars::Helpers::CodeRuby::Tableize

Inherits:
BaseHelper
  • Object
show all
Defined in:
lib/handlebars/helpers/code_ruby/tableize.rb

Overview

Tableize: Creates the name of a table like Rails does when converting models to table names

Instance Method Summary collapse

Methods inherited from BaseHelper

#parse_json, #struct_to_hash, #tokenizer, #wrapper

Instance Method Details

#handlebars_helperObject



29
30
31
# File 'lib/handlebars/helpers/code_ruby/tableize.rb', line 29

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

#parse(value) ⇒ String

Parse will creates the name of a table like Rails does when converting models to table names

Examples:


puts Tableize.new.parse('product category')

product_categories

Parameters:

  • value (String)
    • name of the table

Returns:

  • (String)

    value converted to table case with pluralization



24
25
26
27
# File 'lib/handlebars/helpers/code_ruby/tableize.rb', line 24

def parse(value)
  # tokenizer.parse(value, separator: '_', forced_separator: true).classify
  tokenizer.parse(value).tableize
end