Module: Vedeu::Common Private
- Included in:
- Borders::Refresh, Buffers::Buffer, Buffers::Refresh, Buffers::RefreshContent, Vedeu::Cells::HTML, Vedeu::Coercers::Alignment, Vedeu::Coercers::Coercer, Vedeu::Coercers::ColourAttributes, Vedeu::Colours::Translator, Vedeu::Colours::Validator, Vedeu::Config::API, Configuration, Configuration, Vedeu::Cursors::Refresh, DSL::Align, DSL::Attributes, DSL::Elements, DSL::Text, DSL::Truncate, DSL::View, DSL::Wordwrap, Editor::Cropper, Editor::Delete, Editor::Insert, EscapeSequences::Colours, EscapeSequences::Esc, Events::Aliases, Geometries::DSL, Groups::Refresh, Input::Capture, Input::DSL, Input::Mapper, Input::Read, Interfaces::Clear, Interfaces::ClearContent, Interfaces::DSL, Interfaces::DSL, Models::Row, Output::Compressor, Output::Output, Point, Presentation::Parent, Presentation::Style, Presentation::Styles, Renderers::Options, Repositories::Collection, Repositories::Defaults, Repositories::Repository, Repositories::Store, Runtime::Router, Templating::ViewTemplate, Terminal::Mode, Views::Chars, Views::Lines, Views::Streams, 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, false or empty.
-
#array?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is an Array.
-
#boolean(value) ⇒ Boolean
private
Returns a boolean indicating the value is a boolean.
-
#boolean?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is a Boolean.
-
#empty_value?(value) ⇒ Boolean
private
Returns a boolean indicating the value is empty.
-
#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
(also: #fixnum?)
private
Returns a boolean indicating whether the value is a Fixnum.
-
#positionable?(value) ⇒ Boolean
private
Returns a boolean indicating the value has a position attribute.
-
#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 String.
-
#symbol?(value) ⇒ Boolean
private
Returns a boolean indicating whether the value is a Symbol.
-
#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, false or empty.
17 18 19 |
# File 'lib/vedeu/common.rb', line 17 def absent?(variable) variable == false || !present?(variable) end |
#array?(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 Array.
25 26 27 |
# File 'lib/vedeu/common.rb', line 25 def array?(value) value.is_a?(Array) 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 is 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 |
#empty_value?(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 is empty.
51 52 53 54 55 56 |
# File 'lib/vedeu/common.rb', line 51 def empty_value?(value) return true if value.respond_to?(:empty?) && value.empty? return true if value.nil? false 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.)
62 63 64 |
# File 'lib/vedeu/common.rb', line 62 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.
71 72 73 |
# File 'lib/vedeu/common.rb', line 71 def falsy?(value) Vedeu::Boolean.new(value).false? 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.
79 80 81 |
# File 'lib/vedeu/common.rb', line 79 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.
87 88 89 90 91 92 93 94 95 |
# File 'lib/vedeu/common.rb', line 87 def line_model? if defined?(model) model.is_a?(Vedeu::Views::Line) else false end end |
#numeric?(value) ⇒ Boolean Also known as: fixnum?
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.
101 102 103 |
# File 'lib/vedeu/common.rb', line 101 def numeric?(value) value.is_a?(Fixnum) || value == Float::INFINITY end |
#positionable?(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 has a position attribute.
111 112 113 114 |
# File 'lib/vedeu/common.rb', line 111 def positionable?(value) value.respond_to?(:position) && value.position.is_a?(Vedeu::Geometries::Position) 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.
122 123 124 125 126 127 128 |
# File 'lib/vedeu/common.rb', line 122 def present?(variable) return true if numeric?(variable) return false if variable.nil? || variable == false return false if empty_value?(variable) 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.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vedeu/common.rb', line 143 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.
159 160 161 162 163 164 165 166 167 |
# File 'lib/vedeu/common.rb', line 159 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 String.
173 174 175 |
# File 'lib/vedeu/common.rb', line 173 def string?(value) value.is_a?(String) end |
#symbol?(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 Symbol.
181 182 183 |
# File 'lib/vedeu/common.rb', line 181 def symbol?(value) value.is_a?(Symbol) 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.
190 191 192 |
# File 'lib/vedeu/common.rb', line 190 def truthy?(value) Vedeu::Boolean.new(value).true? 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.
198 199 200 201 202 203 204 205 206 |
# File 'lib/vedeu/common.rb', line 198 def view_model? if defined?(model) model.is_a?(Vedeu::Views::View) else false end end |