Class: Postsvg::Svg::Stroke

Inherits:
Struct
  • Object
show all
Defined in:
lib/postsvg/svg/stroke.rb

Overview

Stroke style value object. Width is a Float (default 1.0), dasharray is an Array of Floats, dashoffset is a Float, linecap / linejoin are Symbols.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dasharrayObject

Returns the value of attribute dasharray

Returns:

  • (Object)

    the current value of dasharray



8
9
10
# File 'lib/postsvg/svg/stroke.rb', line 8

def dasharray
  @dasharray
end

#dashoffsetObject

Returns the value of attribute dashoffset

Returns:

  • (Object)

    the current value of dashoffset



8
9
10
# File 'lib/postsvg/svg/stroke.rb', line 8

def dashoffset
  @dashoffset
end

#linecapObject

Returns the value of attribute linecap

Returns:

  • (Object)

    the current value of linecap



8
9
10
# File 'lib/postsvg/svg/stroke.rb', line 8

def linecap
  @linecap
end

#linejoinObject

Returns the value of attribute linejoin

Returns:

  • (Object)

    the current value of linejoin



8
9
10
# File 'lib/postsvg/svg/stroke.rb', line 8

def linejoin
  @linejoin
end

#miterlimitObject

Returns the value of attribute miterlimit

Returns:

  • (Object)

    the current value of miterlimit



8
9
10
# File 'lib/postsvg/svg/stroke.rb', line 8

def miterlimit
  @miterlimit
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



8
9
10
# File 'lib/postsvg/svg/stroke.rb', line 8

def width
  @width
end

Class Method Details

.parse(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postsvg/svg/stroke.rb', line 10

def self.parse(node)
  width = AttributeParser.number(node["stroke-width"], default: 1.0)
  dasharray_raw = node["stroke-dasharray"]
  dasharray =
    if dasharray_raw && dasharray_raw != "none"
      AttributeParser.number_list(dasharray_raw)
    end
  dashoffset = AttributeParser.number(node["stroke-dashoffset"], default: 0.0)
  linecap = (node["stroke-linecap"] || "butt").to_sym
  linejoin = (node["stroke-linejoin"] || "miter").to_sym
  miterlimit = AttributeParser.number(node["stroke-miterlimit"], default: 10.0)
  new(width: width, dasharray: dasharray, dashoffset: dashoffset,
      linecap: linecap, linejoin: linejoin, miterlimit: miterlimit)
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/postsvg/svg/stroke.rb', line 25

def default?
  width == 1.0 && dasharray.nil? && dashoffset.zero? &&
    linecap == :butt && linejoin == :miter && miterlimit == 10.0
end