Class: Serenity::ImagesProcessor

Inherits:
Object
  • Object
show all
Includes:
Debug
Defined in:
lib/serenity/images_processor.rb

Constant Summary collapse

IMAGE_DIR_NAME =
"Pictures"

Instance Method Summary collapse

Methods included from Debug

#debug?, #debug_dir, #debug_file_name, #debug_file_path

Constructor Details

#initialize(xml_content, context) ⇒ ImagesProcessor

Returns a new instance of ImagesProcessor.



7
8
9
10
11
# File 'lib/serenity/images_processor.rb', line 7

def initialize(xml_content, context)
  @replacements = []
  @images = eval('@images', context)
  @xml_content = xml_content
end

Instance Method Details

#generate_replacementsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/serenity/images_processor.rb', line 13

def generate_replacements
  require 'nokogiri'

  if @images && @images.kind_of?(Hash)
    xml_data = Nokogiri::XML(@xml_content)

    @images.each do |image_name, replacement_path|
      if node = xml_data.xpath("//draw:frame[@draw:name='#{image_name}']/draw:image").first
        placeholder_path = node.attribute('href').value
        odt_image_path = ::File.join(IMAGE_DIR_NAME, ::File.basename(placeholder_path))

        @replacements << [odt_image_path, replacement_path]
      end
    end
  end

  @replacements
end