Sha256: cf22283178825125f8fe6fa3bf2d306bd5181df13f54b4a4bb1d45eeeb1fe353

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

module Vedeu

  # A module for common methods used throughout Vedeu.
  #
  # @api private
  module Common

    # Removes the module part from the expression in the string.
    #
    # @example
    #   demodulize('Vedeu::DSL::Interface') # => "Interface"
    #
    # @param klass [Class|String]
    # @return [void]
    def demodulize(klass)
      klass = klass.to_s

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

    # Converts a class name to a lowercase snake case string.
    #
    # @example
    #   snake_case(MyClassName) # => "my_class_name"
    #   snake_case(NameSpaced::ClassName) # => "name_spaced/class_name"
    #
    # @param name [String]
    # @return [String]
    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

    # Returns a boolean indicating whether a variable has a useful value.
    #
    # @param variable [String|Symbol|Array|Fixnum] The variable to check.
    # @return [Boolean]
    def present?(variable)
      return true if variable.is_a?(Fixnum)
      return true unless variable.nil? || variable.empty?

      false
    end

  end # Common

end # Vedeu

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
vedeu-0.4.56 lib/vedeu/common.rb
vedeu-0.4.55 lib/vedeu/common.rb
vedeu-0.4.54 lib/vedeu/support/common.rb
vedeu-0.4.53 lib/vedeu/support/common.rb
vedeu-0.4.52 lib/vedeu/support/common.rb
vedeu-0.4.51 lib/vedeu/support/common.rb
vedeu-0.4.50 lib/vedeu/support/common.rb
vedeu-0.4.49 lib/vedeu/support/common.rb
vedeu-0.4.48 lib/vedeu/support/common.rb
vedeu-0.4.47 lib/vedeu/support/common.rb
vedeu-0.4.46 lib/vedeu/support/common.rb
vedeu-0.4.45 lib/vedeu/support/common.rb
vedeu-0.4.44 lib/vedeu/support/common.rb
vedeu-0.4.43 lib/vedeu/support/common.rb
vedeu-0.4.42 lib/vedeu/support/common.rb