class DragonflySvg::Analysers::SvgProperties
Public Instance Methods
call(content)
click to toggle source
# File lib/dragonfly_svg/analysers/svg_properties.rb, line 6 def call(content) return {} unless content.ext return {} unless SUPPORTED_FORMATS.include?(content.ext.downcase) return {} unless doc = Nokogiri::XML(content.data) return {} unless node = doc.xpath("//*[name()='svg']").first { 'format' => content.ext.to_s, 'width' => width(node).to_f, 'height' => height(node).to_f, 'id' => id(node) } end
Private Instance Methods
height(node)
click to toggle source
# File lib/dragonfly_svg/analysers/svg_properties.rb, line 30 def height(node) node.get_attribute('height') || viewBox(node)[3] end
id(node)
click to toggle source
# File lib/dragonfly_svg/analysers/svg_properties.rb, line 34 def id(node) node.get_attribute('id') end
viewBox(node)
click to toggle source
# File lib/dragonfly_svg/analysers/svg_properties.rb, line 22 def viewBox(node) node.get_attribute('viewBox').to_s.split(/\s+/) end
width(node)
click to toggle source
# File lib/dragonfly_svg/analysers/svg_properties.rb, line 26 def width(node) node.get_attribute('width') || viewBox(node)[2] end