Class: SvgInlineFileExtractor::SvgFile

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_inline_file_extractor/svg_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_string) ⇒ SvgFile

Returns a new instance of SvgFile.

Parameters:

  • xml_string (String)

    should be a full raw SVG file



22
23
24
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 22

def initialize(xml_string)
  self.xml_string = xml_string
end

Instance Attribute Details

#xml_stringObject

Returns the value of attribute xml_string.



19
20
21
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 19

def xml_string
  @xml_string
end

Class Method Details

.binary_images(xml_string) ⇒ Object

Parameters:

  • xml_string (String)

    should be a full raw SVG file



9
10
11
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 9

def binary_images(xml_string)
  new(xml_string).binary_images
end

.inline_images(xml_string) ⇒ Object

Parameters:

  • xml_string (String)

    should be a full raw SVG file



14
15
16
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 14

def inline_images(xml_string)
  new(xml_string).inline_images
end

Instance Method Details

#binary_imagesArray<String>

Returns an array of binary strings containing the images in the SVG file.

Returns:

  • (Array<String>)

    an array of binary strings containing the images in the SVG file



27
28
29
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 27

def binary_images
  inline_images.map(&:binary_image)
end

#inline_imagesArray<InlineImage>

Returns an array of the inline images found in the document.

Returns:

  • (Array<InlineImage>)

    an array of the inline images found in the document

See Also:



42
43
44
45
46
47
48
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 42

def inline_images
  image_elements.map do |element|
    if (image = InlineImage.new(element)).inline_image?
      image
    end
  end.compact
end

#nokogiri_documentNokogiri::XML

Returns a nokogiri XML document wrapper.

Returns:

  • (Nokogiri::XML)

    a nokogiri XML document wrapper



32
33
34
35
36
37
38
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 32

def nokogiri_document
  @nokogiri_document ||= begin
    doc = Nokogiri::XML(xml_string)
    doc.remove_namespaces!
    doc
  end
end