Module: Vedeu::Common
- Included in:
- Borders::Border, Borders::Refresh, Buffers::Refresh, Vedeu::Clear::Interface, Vedeu::Config::API, Vedeu::Cursors::Refresh, DSL::View, DSL::View, Editor::Cropper, Editor::Editor, EscapeSequences::Esc, Events::Aliases, Geometry::DSL, Groups::Refresh, Input::DSL, Interfaces::DSL, Interfaces::DSL, Output::Compressor, Presentation::Style, Repositories::Model, Repositories::Repository, Repositories::Store, Runtime::Router, Templating::ViewTemplate, Views::HTMLChar
- Defined in:
- lib/vedeu/common.rb
Overview
A module for common methods used throughout Vedeu.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
Returns a boolean indicating whether a variable is nil or empty.
-
#demodulize(klass) ⇒ String
Removes the module part from the expression in the string.
-
#present?(variable) ⇒ Boolean
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(name) ⇒ String
Converts a class name to a lowercase snake case string.
Instance Method Details
#absent?(variable) ⇒ Boolean
Returns a boolean indicating whether a variable is nil or empty.
12 13 14 |
# File 'lib/vedeu/common.rb', line 12 def absent?(variable) !present?(variable) end |
#demodulize(klass) ⇒ String
Removes the module part from the expression in the string.
23 24 25 26 27 |
# File 'lib/vedeu/common.rb', line 23 def demodulize(klass) klass = klass.to_s klass[(klass.rindex('::') + 2)..-1] end |
#present?(variable) ⇒ Boolean
Returns a boolean indicating whether a variable has a useful value.
35 36 37 38 39 40 |
# File 'lib/vedeu/common.rb', line 35 def present?(variable) return true if variable.is_a?(Fixnum) return true unless variable.nil? || variable.empty? false end |
#snake_case(name) ⇒ String
Converts a class name to a lowercase snake case string.
51 52 53 54 55 56 57 58 |
# File 'lib/vedeu/common.rb', line 51 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 |