Class: Maglev::Content::Color

Inherits:
Base
  • Object
show all
Defined in:
app/components/maglev/content/color.rb

Instance Attribute Summary

Attributes inherited from Base

#content, #scope, #setting

Instance Method Summary collapse

Methods inherited from Base

#asset_host, #dom_data, #initialize, #tag, #tag_data, #tag_id, #to_s

Constructor Details

This class inherits a constructor from Maglev::Content::Base

Instance Method Details

#brightnessObject



14
15
16
17
# File 'app/components/maglev/content/color.rb', line 14

def brightness
  r, g, b = content.match(/^#(..)(..)(..)$/).captures.map(&:hex)
  (r * 299 + g * 587 + b * 114) / 1000.0
end

#dark?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/components/maglev/content/color.rb', line 6

def dark?
  brightness < 128
end

#light?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/components/maglev/content/color.rb', line 10

def light?
  !dark?
end