Class: Emfsvg::Svg::Paint

Inherits:
Object
  • Object
show all
Defined in:
lib/emfsvg/svg/paint.rb

Overview

Parsed SVG stroke= and fill= attribute values, mapped to a value object the translation layer can consume.

Paint is a thin struct: it carries a Color (which may be the NULL sentinel for "none") and the original brush/pen style bits.

Constant Summary collapse

SOLID =
0
NULL =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color:, style: SOLID) ⇒ Paint

Returns a new instance of Paint.



14
15
16
17
# File 'lib/emfsvg/svg/paint.rb', line 14

def initialize(color:, style: SOLID)
  @style = style
  @color = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



19
20
21
# File 'lib/emfsvg/svg/paint.rb', line 19

def color
  @color
end

#styleObject (readonly)

Returns the value of attribute style.



19
20
21
# File 'lib/emfsvg/svg/paint.rb', line 19

def style
  @style
end

Class Method Details

.from_fill(value) ⇒ Object



25
26
27
28
# File 'lib/emfsvg/svg/paint.rb', line 25

def self.from_fill(value)
  color = Color.parse(value)
  new(style: color.null? ? NULL : SOLID, color: color)
end

.from_stroke(value) ⇒ Object



30
31
32
33
# File 'lib/emfsvg/svg/paint.rb', line 30

def self.from_stroke(value)
  color = Color.parse(value)
  new(style: color.null? ? NULL : SOLID, color: color)
end

Instance Method Details

#null?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/emfsvg/svg/paint.rb', line 21

def null?
  style == NULL || color.null?
end