Module: Vedeu::Common Private
- Included in:
- Borders::Refresh, Buffers::Refresh, Vedeu::Cells::HTML, Vedeu::Coercers::Alignment, Vedeu::Coercers::Colour, Vedeu::Coercers::ColourAttributes, Vedeu::Colours::Translator, Vedeu::Colours::Validator, Configuration, Vedeu::Cursors::Refresh, DSL::Align, DSL::Attributes, DSL::Elements, DSL::Text, DSL::Truncate, DSL::View, DSL::Wordwrap, Editor::Cropper, Editor::Delete, Editor::Insert, Editor::Line, Editor::Lines, EscapeSequences::Esc, Events::Aliases, Geometries::DSL, Groups::Refresh, Input::DSL, Input::Mapper, Input::Read, Interfaces::Clear, Interfaces::DSL, Interfaces::DSL, Models::Row, Output::Compressor, Output::Output, Presentation::Style, Presentation::Style, Presentation::Styles, Renderers::Options, Repositories::Defaults, Repositories::Model, Repositories::Repository, Repositories::Store, Runtime::Router, Templating::ViewTemplate, Terminal::Mode, Views::Value::InstanceMethods
- Defined in:
- lib/vedeu/common.rb
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
-
#absent?(variable) ⇒ Boolean
private
Returns a boolean indicating whether a variable is nil or empty.
-
#become(klass, attributes) ⇒ Class
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is a Boolean.
-
#escape?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value should be considered false.
-
#hash?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is a Hash.
-
#line_model? ⇒ Boolean
private
Returns a boolean indicating the model is a Views::Line.
-
#numeric?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(klass) ⇒ String
private
Converts a class name to a lowercase snake case string.
-
#stream_model? ⇒ Boolean
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is a Fixnum.
-
#truthy?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
private
Returns a boolean indicating the model is a Views::View.
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.
16 17 18 |
# File 'lib/vedeu/common.rb', line 16 def absent?(variable) !present?(variable) end |
#become(klass, attributes) ⇒ Class
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 one class into another.
25 26 27 |
# File 'lib/vedeu/common.rb', line 25 def become(klass, attributes) klass.new(attributes) end |
#boolean(value) ⇒ 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 the value was a boolean.
33 34 35 36 37 |
# File 'lib/vedeu/common.rb', line 33 def boolean(value) return value if boolean?(value) return false if falsy?(value) return true if truthy?(value) end |
#boolean?(value) ⇒ 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 the value is a Boolean.
43 44 45 |
# File 'lib/vedeu/common.rb', line 43 def boolean?(value) value.is_a?(TrueClass) || value.is_a?(FalseClass) end |
#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
51 52 53 |
# File 'lib/vedeu/common.rb', line 51 def escape?(value) value.is_a?(Vedeu::Cells::Escape) || value.is_a?(Vedeu::Cells::Cursor) end |
#falsy?(value) ⇒ 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 the value should be considered false.
60 61 62 |
# File 'lib/vedeu/common.rb', line 60 def falsy?(value) value.nil? || value.is_a?(FalseClass) end |
#hash?(value) ⇒ 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 the value is a Hash.
68 69 70 |
# File 'lib/vedeu/common.rb', line 68 def hash?(value) value.is_a?(Hash) end |
#line_model? ⇒ 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 the model is a Views::Line.
76 77 78 79 80 81 82 83 84 |
# File 'lib/vedeu/common.rb', line 76 def line_model? if defined?(model) model.is_a?(Vedeu::Views::Line) else false end end |
#numeric?(value) ⇒ 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 the value is a Fixnum.
90 91 92 |
# File 'lib/vedeu/common.rb', line 90 def numeric?(value) value.is_a?(Fixnum) 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.
100 101 102 103 104 105 106 |
# File 'lib/vedeu/common.rb', line 100 def present?(variable) return true if numeric?(variable) return false if variable.nil? return false if variable.respond_to?(:empty?) && variable.empty? true end |
#snake_case(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.
Converts a class name to a lowercase snake case string.
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/vedeu/common.rb', line 121 def snake_case(klass) str = klass.is_a?(Module) ? klass.name : klass str.split(/::/).map do |namespace| *upper, _ = namespace.split(/([A-Z]+)/).reject(&:empty?).map do |chars| chars =~ /\p{Lower}/ ? [chars, '_'] : chars end.flatten upper.map(&:downcase).join end.join('/') end |
#stream_model? ⇒ 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 the model is a Views::Stream.
137 138 139 140 141 142 143 144 145 |
# File 'lib/vedeu/common.rb', line 137 def stream_model? if defined?(model) model.is_a?(Vedeu::Views::Stream) else false end end |
#string?(value) ⇒ 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 the value is a Fixnum.
151 152 153 |
# File 'lib/vedeu/common.rb', line 151 def string?(value) value.is_a?(String) end |
#truthy?(value) ⇒ 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 the value should be considered true.
160 161 162 |
# File 'lib/vedeu/common.rb', line 160 def truthy?(value) !falsy?(value) end |
#view_model? ⇒ 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 the model is a Views::View.
168 169 170 171 172 173 174 175 176 |
# File 'lib/vedeu/common.rb', line 168 def view_model? if defined?(model) model.is_a?(Vedeu::Views::View) else false end end |