Class: Postsvg::Svg::Paint
- Inherits:
-
Struct
- Object
- Struct
- Postsvg::Svg::Paint
- Defined in:
- lib/postsvg/svg/paint.rb
Overview
Paint value object: resolves a CSS-style paint value to either a Color instance, a paint-server URL reference (gradient / pattern id), or :none.
Instance Attribute Summary collapse
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#kind ⇒ Object
Returns the value of attribute kind
8 9 10 |
# File 'lib/postsvg/svg/paint.rb', line 8 def kind @kind end |
#value ⇒ Object
Returns the value of attribute value
8 9 10 |
# File 'lib/postsvg/svg/paint.rb', line 8 def value @value end |
Class Method Details
.parse(text) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/postsvg/svg/paint.rb', line 9 def self.parse(text) return Paint.new(kind: :none) if text.nil? || text.strip == "none" if text&.start_with?("url(") id = text.match(/url\(\s*["']?#([^)\s"']+)/) return Paint.new(kind: :reference, value: id && id[1]) end color = begin ::Postsvg::Color.parse(text.to_s) rescue ArgumentError nil end if color Paint.new(kind: :color, value: color) else Paint.new(kind: :none) end end |
Instance Method Details
#color? ⇒ Boolean
31 |
# File 'lib/postsvg/svg/paint.rb', line 31 def color? = kind == :color |
#none? ⇒ Boolean
29 |
# File 'lib/postsvg/svg/paint.rb', line 29 def none? = kind == :none |
#reference? ⇒ Boolean
30 |
# File 'lib/postsvg/svg/paint.rb', line 30 def reference? = kind == :reference |