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 or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:



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.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.



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.

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

#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:



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.

Parameters:

  • value (void)

Returns:



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.

Parameters:

  • value (Hash|void)

Returns:



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.

Returns:



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.

Parameters:

  • value (Fixnum|void)

Returns:



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.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:



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.

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)


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.

Returns:



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.

Parameters:

  • value (String|void)

Returns:



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.

Parameters:

  • value (void)

Returns:



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.

Returns:



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