Module: Powerpoint::Util

Instance Method Summary collapse

Instance Method Details

#copy_media(extract_path, image_path) ⇒ Object



24
25
26
27
28
# File 'lib/powerpoint/util.rb', line 24

def copy_media(extract_path, image_path)
  image_name = File.basename(image_path)
  dest_path = "#{extract_path}/ppt/media/#{image_name}"
  FileUtils.copy_file(image_path, dest_path) unless File.exist?(dest_path)
end

#pixle_to_pt(px) ⇒ Object



4
5
6
# File 'lib/powerpoint/util.rb', line 4

def pixle_to_pt(px)
  px * 12700
end

#read_template(filename) ⇒ Object



16
17
18
# File 'lib/powerpoint/util.rb', line 16

def read_template(filename)
  File.read("#{Powerpoint::VIEW_PATH}/#{filename}")
end

#render_view(template_name, path) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/powerpoint/util.rb', line 8

def render_view(template_name, path)
  view_contents = read_template(template_name)
  renderer = ERB.new(view_contents)
  data = renderer.result(binding)

  File.open(path, 'w') { |f| f << data }
end

#require_arguments(required_argements, argements) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
# File 'lib/powerpoint/util.rb', line 20

def require_arguments(required_argements, argements)
  raise ArgumentError unless required_argements.all? {|required_key| argements.keys.include? required_key}
end