Class: Vedeu::Coercers::ColourAttributes Private

Inherits:
Object
  • Object
show all
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

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

Parameters:

  • value (Hash)


24
25
26
# File 'lib/vedeu/coercers/colour_attributes.rb', line 24

def initialize(value)
  @value = value
end

Instance Attribute Details

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

  • (Hash)


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.

Parameters:

  • value (Hash)

Returns:

  • (Hash)


18
19
20
# File 'lib/vedeu/coercers/colour_attributes.rb', line 18

def self.coerce(value)
  new(value).coerce
end

Instance Method Details

#backgroundNilClass|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.

Returns:

  • (NilClass|String)


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.

Returns:



74
75
76
# File 'lib/vedeu/coercers/colour_attributes.rb', line 74

def background?
  valid?(background)
end

#coerceHash

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:

  • (Hash)

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



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.

Parameters:

  • colour (void)

Returns:



55
56
57
# File 'lib/vedeu/coercers/colour_attributes.rb', line 55

def coerced?(colour)
  colour.is_a?(klass)
end

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

  • (Hash)


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_foregroundHash (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:

  • (Hash)


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

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

  • (Hash)


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.

Returns:



84
85
86
# File 'lib/vedeu/coercers/colour_attributes.rb', line 84

def colour?
  value.key?(:colour)
end

#foregroundNilClass|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.

Returns:

  • (NilClass|String)


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.

Returns:



103
104
105
# File 'lib/vedeu/coercers/colour_attributes.rb', line 103

def foreground?
  valid?(foreground)
end

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

  • (Class)


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.

Parameters:

  • colour (void)

Returns:



114
115
116
# File 'lib/vedeu/coercers/colour_attributes.rb', line 114

def valid?(colour)
  Vedeu::Colours::Validator.valid?(colour)
end