Class: Prismic::Fragments::Color

Inherits:
Fragment
  • Object
show all
Defined in:
lib/prismic/fragments/color.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Fragment

#as_text

Constructor Details

#initialize(value) ⇒ Color

Returns a new instance of Color.



7
8
9
# File 'lib/prismic/fragments/color.rb', line 7

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/prismic/fragments/color.rb', line 5

def value
  @value
end

Class Method Details

.asRGB(value) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/prismic/fragments/color.rb', line 21

def self.asRGB(value)
  {
    'red'   => value[0..1].to_i(16),
    'green' => value[2..3].to_i(16),
    'blue'  => value[4..5].to_i(16)
  }
end

.valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/prismic/fragments/color.rb', line 39

def self.valid?(value)
  /(\h{2})(\h{2})(\h{2})/ ===  value
end

Instance Method Details

#as_html(link_resolver = nil) ⇒ String

Generate an HTML representation of the fragment

Parameters:

  • link_resolver (LinkResolver) (defaults to: nil)

    The LinkResolver used to build application's specific URL

Returns:

  • (String)

    the HTML representation



35
36
37
# File 'lib/prismic/fragments/color.rb', line 35

def as_html(link_resolver=nil)
  %(<span class="color">##@value</span>)
end

#asRGBHash

Returns the RGB values in a Hash

Examples:

color.asRGB  # => {'red' => 123, 'green' => 123, 'blue' => 123}

Returns:

  • (Hash)


17
18
19
# File 'lib/prismic/fragments/color.rb', line 17

def asRGB
  Fragments::Color.asRGB(@value)
end