Class: Vedeu::Coercers::ColourAttributes Private
- Inherits:
-
Object
- Object
- Vedeu::Coercers::ColourAttributes
- Includes:
- Vedeu::Common
- Defined in:
- lib/vedeu/coercers/colour_attributes.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.
Coerces a colour options hash into: an empty hash, or a hash containing either or both background and foreground keys.
Instance Attribute Summary collapse
- #value ⇒ Hash readonly protected private
Class Method Summary collapse
- .coerce(value) ⇒ Hash private
Instance Method Summary collapse
- #background ⇒ NilClass|String private private
- #background? ⇒ Boolean private private
- #coerce ⇒ Hash private
- #coerced?(colour) ⇒ Boolean private private
- #coerced_background ⇒ Hash private private
- #coerced_foreground ⇒ Hash private private
- #colour ⇒ Hash private private
- #colour? ⇒ Boolean private private
- #foreground ⇒ NilClass|String private private
- #foreground? ⇒ Boolean private private
- #initialize(value) ⇒ Hash constructor private
- #klass ⇒ Class private private
- #valid?(colour) ⇒ Boolean private 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) ⇒ Hash
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/coercers/colour_attributes.rb', line 24 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Hash (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.
49 50 51 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 49 def value @value end |
Class Method Details
.coerce(value) ⇒ Hash
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/coercers/colour_attributes.rb', line 18 def self.coerce(value) new(value).coerce end |
Instance Method Details
#background ⇒ NilClass|String (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.
69 70 71 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 69 def background value[:background] end |
#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.
74 75 76 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 74 def background? valid?(background) end |
#coerce ⇒ Hash
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 30 def coerce raise Vedeu::Error::InvalidSyntax unless hash?(value) if colour? && hash?(colour) Vedeu::Coercers::ColourAttributes.coerce(colour) elsif colour? && coerced?(colour) colour.attributes else coerced_background.merge(coerced_foreground) end end |
#coerced?(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.
55 56 57 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 55 def coerced?(colour) colour.is_a?(klass) end |
#coerced_background ⇒ Hash (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.
60 61 62 63 64 65 66 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 60 def coerced_background return {} unless background? { background: background, } end |
#coerced_foreground ⇒ Hash (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.
89 90 91 92 93 94 95 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 89 def coerced_foreground return {} unless foreground? { foreground: foreground, } end |
#colour ⇒ Hash (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.
79 80 81 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 79 def colour value[:colour] 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.
84 85 86 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 84 def colour? value.key?(:colour) end |
#foreground ⇒ NilClass|String (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.
98 99 100 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 98 def foreground value[:foreground] 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.
103 104 105 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 103 def foreground? valid?(foreground) end |
#klass ⇒ Class (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.
108 109 110 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 108 def klass Vedeu::Colours::Colour end |
#valid?(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.
114 115 116 |
# File 'lib/vedeu/coercers/colour_attributes.rb', line 114 def valid?(colour) Vedeu::Colours::Validator.valid?(colour) end |