Class: Vedeu::Colours::Validator Private
- Inherits:
-
Object
- Object
- Vedeu::Colours::Validator
- 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
- #value ⇒ String readonly protected private
Class Method Summary collapse
- .valid?(value) ⇒ Boolean private
Instance Method Summary collapse
- #background? ⇒ Boolean private private
- #colour? ⇒ Boolean private private
- #foreground? ⇒ Boolean private private
- #initialize(value) ⇒ Vedeu::Colours::Validator constructor private
-
#named? ⇒ Boolean
private
Returns a boolean indicating whether the colour provided is a valid named colour.
-
#numbered? ⇒ Boolean
private
Returns a boolean indicating whether the value is within the range of valid terminal numbered colours.
-
#rgb? ⇒ Boolean
private
Returns a boolean indicated whether the colour is a valid HTML/CSS colour.
- #valid? ⇒ Boolean private
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.
24 25 26 |
# File 'lib/vedeu/colours/validator.rb', line 24 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ String (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.
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.
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.
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.
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.
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.
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.
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.
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.
55 56 57 |
# File 'lib/vedeu/colours/validator.rb', line 55 def valid? background? || colour? || foreground? || rgb? || named? || numbered? end |