Class: Dovado::Utilities Private

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/dovado/utilities.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Library utilities.

Since:

  • 1.0.0

Class Method Summary collapse

Class Method Details

.array_to_sentence(ary, options = {:words_connector => ', ', :two_words_connector => ' and ', :last_word_connector => ' and '}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a sentence from an array.

Ported from ActiveSupport:

  • File activesupport/lib/active_support/core_ext/array/conversions.rb, line 59

Parameters:

  • ary (Array)

    the Array to make a sentence of.

  • options (Hash) (defaults to: {:words_connector => ', ', :two_words_connector => ' and ', :last_word_connector => ' and '})

    optional settings.

Options Hash (options):

  • :words_connector (String)
  • :two_words_connector (String)
  • :last_word_connector (String)

Since:

  • 1.0.0



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dovado/utilities.rb', line 27

def self.array_to_sentence(ary, options = {:words_connector     => ', ', :two_words_connector => ' and ', :last_word_connector => ' and '})
  case ary.length
  when 0
    ''
  when 1
    ary[0].to_s.dup
  when 2
    "#{ary[0]}#{options[:two_words_connector]}#{ary[1]}"
  else
    "#{ary[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{ary[-1]}"
  end
end

.name_to_sym(name = nil) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert a key name to symbol.

Parameters:

  • name (String) (defaults to: nil)

    the key name to convert.

Returns:

  • (Symbol)

    the key name converted to a symbol.

Since:

  • 1.0.0



13
14
15
# File 'lib/dovado/utilities.rb', line 13

def self.name_to_sym(name=nil)
  name.downcase.tr(' ', '_').to_sym
end