module Typekit::Helper

Public Class Methods

constantize(object) click to toggle source

Constructs a symbol suitable for looking up modules among the constants defined in a module.

@param object [String, Symbol] @return [Symbol]

# File lib/typekit/helper.rb, line 38
def self.constantize(object)
  object.to_s.sub(/^.*::/, '').capitalize.to_sym
end
extract_array!(array) click to toggle source

Removes and returns the last element of the given array if that element is an array; otherwise, a new array is returned.

@param array [Array] @return [Array]

# File lib/typekit/helper.rb, line 74
def self.extract_array!(array)
  array.last.is_a?(Array) ? array.pop : {}
end
extract_hash!(array) click to toggle source

Removes and returns the last element of the given array if that element is a hash; otherwise, a new hash is returned.

@param array [Array] @return [Hash]

# File lib/typekit/helper.rb, line 65
def self.extract_hash!(array)
  array.last.is_a?(Hash) ? array.pop : {}
end
pluralize(word) click to toggle source

Returns the plural form of the given word.

@param word [String] @return [String]

# File lib/typekit/helper.rb, line 7
def self.pluralize(word)
  case word
  when /^.*s$/
    word
  when /^(?<root>.*)y$/
    "#{Regexp.last_match(:root)}ies"
  else
    "#{word}s"
  end
end
singularize(word) click to toggle source

Returns the singular form of the given word.

@param word [String] @return [String]

# File lib/typekit/helper.rb, line 22
def self.singularize(word)
  case word
  when /^(?<root>.*)ies$/
    "#{Regexp.last_match(:root)}y"
  when /^(?<root>.*)s$/
    Regexp.last_match(:root)
  else
    word
  end
end
symbolize_keys(hash) click to toggle source

Copies the given hash while converting its keys into symbols.

@param hash [Hash] @return [Hash]

# File lib/typekit/helper.rb, line 56
def self.symbolize_keys(hash)
  Hash[hash.map { |k, v| [k.to_sym, v] }]
end
tokenize(object, options = {}) click to toggle source

Constructs a symbolic representation of the given object.

@param object @option options [Boolean] :pluralize (true) indicates if the result

should be plural
# File lib/typekit/helper.rb, line 47
def self.tokenize(object, options = {})
  name = object.to_s.sub(/^.*::/, '').downcase
  (options.fetch(:pluralize, true) ? pluralize(name) : name).to_sym
end