Class: SvgInlineFileExtractor::SvgFile
- Inherits:
-
Object
- Object
- SvgInlineFileExtractor::SvgFile
- Defined in:
- lib/svg_inline_file_extractor/svg_file.rb
Instance Attribute Summary collapse
-
#xml_string ⇒ Object
Returns the value of attribute xml_string.
Class Method Summary collapse
Instance Method Summary collapse
-
#binary_images ⇒ Array<String>
An array of binary strings containing the images in the SVG file.
-
#initialize(xml_string) ⇒ SvgFile
constructor
A new instance of SvgFile.
-
#inline_images(all = false) ⇒ Array<InlineImage>
An array of the inline images found in the document.
-
#nokogiri_document ⇒ Nokogiri::XML
A nokogiri XML document wrapper.
-
#rendered_svg ⇒ Object
The rendered nokogiri_document.
Constructor Details
#initialize(xml_string) ⇒ SvgFile
Returns a new instance of SvgFile.
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_string ⇒ Object
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
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
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_images ⇒ Array<String>
Returns 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_images(all = false) ⇒ Array<InlineImage>
Returns an array of the inline images found in the document.
43 44 45 46 47 48 49 50 |
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 43 def inline_images(all = false) image_elements.map do |element| image = InlineImage.new(element) if all || image.inline_image? image end end.compact end |
#nokogiri_document ⇒ Nokogiri::XML
Returns 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 |
#rendered_svg ⇒ Object
Note:
text “ ” will be replaced with newlines to allow newlines in Base64 encoded strings.
Returns the rendered nokogiri_document.
55 56 57 |
# File 'lib/svg_inline_file_extractor/svg_file.rb', line 55 def rendered_svg nokogiri_document.to_s.gsub(' ', "\n") end |