Class: InlineSvg::TransformPipeline::Transformations::Size

Inherits:
Transformation
  • Object
show all
Defined in:
lib/inline_svg/transform_pipeline/transformations/size.rb

Instance Attribute Summary

Attributes inherited from Transformation

#value

Instance Method Summary collapse

Methods inherited from Transformation

create_with_value, #initialize

Constructor Details

This class inherits a constructor from InlineSvg::TransformPipeline::Transformations::Transformation

Instance Method Details

#height_of(value) ⇒ Object



15
16
17
# File 'lib/inline_svg/transform_pipeline/transformations/size.rb', line 15

def height_of(value)
  value.split(/\*/).map(&:strip)[1] || width_of(value)
end

#transform(doc) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/inline_svg/transform_pipeline/transformations/size.rb', line 3

def transform(doc)
  doc = Nokogiri::XML::Document.parse(doc.to_html)
  svg = doc.at_css 'svg'
  svg['width'] = width_of(self.value)
  svg['height'] = height_of(self.value)
  doc
end

#width_of(value) ⇒ Object



11
12
13
# File 'lib/inline_svg/transform_pipeline/transformations/size.rb', line 11

def width_of(value)
  value.split(/\*/).map(&:strip)[0]
end