Module: Vedeu::Common
- Included in:
- Borders::Border, Borders::Render, Buffers::Refresh, Vedeu::Config::API, DSL::Interface, DSL::Interface, DSL::Keymap, DSL::View, DSL::View, Editor::Editor, Model, Presentation::Style, RefreshGroup, Repository, 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
-
#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
#demodulize(klass) ⇒ String
Removes the module part from the expression in the string.
14 15 16 17 18 |
# File 'lib/vedeu/common.rb', line 14 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.
43 44 45 46 47 48 |
# File 'lib/vedeu/common.rb', line 43 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.
28 29 30 31 32 33 34 35 |
# File 'lib/vedeu/common.rb', line 28 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 |