Module: Vedeu::Common Private

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

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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:



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.

Parameters:

  • value (Array|void)

Returns:



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.

Parameters:

  • value (void)

Returns:



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.

Parameters:

Returns:



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.

Parameters:

  • value (void)

Returns:



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.)

Returns:



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.

Parameters:

  • value (void)

Returns:



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.

Parameters:

  • value (Hash|void)

Returns:



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.

Returns:



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.

Parameters:

  • value (Fixnum|void)

Returns:



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.

Parameters:

  • value (void)

Returns:



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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:



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.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

  • (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.

Returns:



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.

Parameters:

  • value (String|void)

Returns:



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.

Parameters:

  • value (Symbol|void)

Returns:



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.

Parameters:

  • value (void)

Returns:



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.

Returns:



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