Sha256: ef179d06f9e18acd176c42be18f40376a621929ddb8506546bd6707f98d1edb3
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
module Vedeu module Coercers # Converts a given value into a {Vedeu::Colours::Colour} if # possible. # # @api private # class Colour include Vedeu::Common # @param (see #initialize) # @return (see #coerce) def self.coerce(value) new(value).coerce end # @param value [void] # @return [Vedeu::Coercers::Colour] def initialize(value) @value = value end # @raise [Vedeu::Error::Fatal] When the value cannot be coerced. # @return [void] def coerce if absent?(value) Vedeu::Colours::Colour.new elsif background? Vedeu::Colours::Colour.new(background: value) elsif colour? value elsif foreground? Vedeu::Colours::Colour.new(foreground: value) elsif hash?(value) attributes = Vedeu::Coercers::ColourAttributes.coerce(value) Vedeu::Colours::Colour.new(attributes) else fail Vedeu::Error::Fatal, 'Vedeu cannot coerce this colour.'.freeze end end protected # @!attribute [r] value # @return [void] attr_reader :value private # @return [Boolean] def background? value.is_a?(Vedeu::Colours::Background) end # @return [Boolean] def colour? value.is_a?(Vedeu::Colours::Colour) end # @return [Boolean] def foreground? value.is_a?(Vedeu::Colours::Foreground) end end # Colour end # Coercers end # Vedeu
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.8.0 | lib/vedeu/coercers/colour.rb |