Class: Vedeu::Colours::Validator Private

Inherits:
Object
  • Object
show all
Includes:
Vedeu::Common
Defined in:
lib/vedeu/colours/validator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Validates the value as a valid colour string in HTML/CSS format, e.g. ‘#123456’.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Vedeu::Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Constructor Details

#initialize(value) ⇒ Vedeu::Colours::Validator

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.

Parameters:

  • value (String)


24
25
26
# File 'lib/vedeu/colours/validator.rb', line 24

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueString (readonly, protected)

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:

  • (String)


63
64
65
# File 'lib/vedeu/colours/validator.rb', line 63

def value
  @value
end

Class Method Details

.valid?(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.

Parameters:

  • value (String)

Returns:



18
19
20
# File 'lib/vedeu/colours/validator.rb', line 18

def self.valid?(value)
  new(value).valid?
end

Instance Method Details

#background?Boolean (private)

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:



68
69
70
# File 'lib/vedeu/colours/validator.rb', line 68

def background?
  value.is_a?(Vedeu::Colours::Background)
end

#colour?Boolean (private)

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:



73
74
75
# File 'lib/vedeu/colours/validator.rb', line 73

def colour?
  value.is_a?(Vedeu::Colours::Colour)
end

#foreground?Boolean (private)

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:



78
79
80
# File 'lib/vedeu/colours/validator.rb', line 78

def foreground?
  value.is_a?(Vedeu::Colours::Foreground)
end

#named?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 colour provided is a valid named colour.

Returns:



32
33
34
# File 'lib/vedeu/colours/validator.rb', line 32

def named?
  Vedeu.esc.valid_name?(value)
end

#numbered?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 within the range of valid terminal numbered colours.

Returns:



40
41
42
# File 'lib/vedeu/colours/validator.rb', line 40

def numbered?
  numeric?(value) && value >= 0 && value <= 255
end

#rgb?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 indicated whether the colour is a valid HTML/CSS colour.

Returns:



48
49
50
51
52
# File 'lib/vedeu/colours/validator.rb', line 48

def rgb?
  return true if value =~ /^#([A-Fa-f0-9]{6})$/

  false
end

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



55
56
57
# File 'lib/vedeu/colours/validator.rb', line 55

def valid?
  background? || colour? || foreground? || rgb? || named? || numbered?
end