Class: Klaro::Client::Story

Inherits:
Resource
  • Object
show all
Defined in:
lib/klaro/client/resource/story.rb

Instance Method Summary collapse

Instance Method Details

#download_and_relocate_attachments(root_path, target_folder, client) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/klaro/client/resource/story.rb', line 5

def download_and_relocate_attachments(root_path, target_folder, client)
  as = self.attachments.map do |attachment|
    url = attachment["url"]
    url += "?n=" + URI.encode_www_form_component(attachment["filename"]) unless url =~ /\?n=/
    path = handle_image(url, root_path, target_folder, client)
    attachment.merge("url" => path)
  end
  self.class.new(self.to_h.merge(
    attachments: as
  ))
rescue => ex
  puts ex.message
  puts ex.backtrace.join("\n")
  raise
end

#download_and_relocate_images(root_path, target_folder, client) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/klaro/client/resource/story.rb', line 21

def download_and_relocate_images(root_path, target_folder, client)
  spec = self.specification.gsub(%r{!\[([^\]]*)\]\(([^\)]*)\)}) do
    m = Regexp.last_match
    label, url = m[1], m[2]
    image_relative_path = handle_image(url, root_path, target_folder, client)
    "![#{label}](#{image_relative_path})"
  end
  self.class.new(self.to_h.merge(
    specification: spec
  ))
end