Class: GeoPattern::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_pattern/color.rb

Instance Method Summary collapse

Constructor Details

#initialize(html_color) ⇒ Color

Returns a new instance of Color.



11
12
13
# File 'lib/geo_pattern/color.rb', line 11

def initialize(html_color)
  @color = ::Color::RGB.from_html html_color
end

Instance Method Details

#to_htmlObject



23
24
25
# File 'lib/geo_pattern/color.rb', line 23

def to_html
  color.html
end

#to_svgObject



15
16
17
18
19
20
21
# File 'lib/geo_pattern/color.rb', line 15

def to_svg
  r = (color.r * 255).round
  g = (color.g * 255).round
  b = (color.b * 255).round

  format("rgb(%<r>d, %<g>d, %<b>d)", r: r, g: g, b: b)
end