Module: Vedeu::Common Private

Overview

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

A module for common methods used throughout Vedeu.

Instance Method Summary collapse

Instance Method Details

#absent?(variable) ⇒ Boolean

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.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)


14
15
16
# File 'lib/vedeu/common.rb', line 14

def absent?(variable)
  !present?(variable)
end

#demodulize(klass) ⇒ String

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.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)


25
26
27
28
29
# File 'lib/vedeu/common.rb', line 25

def demodulize(klass)
  klass = klass.to_s

  klass[(klass.rindex('::') + 2)..-1]
end

#present?(variable) ⇒ Boolean

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.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/vedeu/common.rb', line 37

def present?(variable)
  return true if variable.is_a?(Fixnum)
  return true unless variable.nil? || variable.empty?

  false
end

#snake_case(name) ⇒ String

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.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)


53
54
55
56
57
58
59
60
# File 'lib/vedeu/common.rb', line 53

def snake_case(name)
  name.gsub!(/::/, '/')
  name.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
  name.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  name.tr!('-', '_')
  name.downcase!
  name
end