class SlideHero::RemoteImage
Attributes
alt_text[R]
as[R]
destination[R]
height[R]
image_class[R]
location[R]
width[R]
Public Class Methods
new(location, alt_text="", image_class:Image, width:nil, height:nil, destination: 'images', as:nil)
click to toggle source
# File lib/slide_hero/remote_image.rb, line 5 def initialize(location, alt_text="", image_class:Image, width:nil, height:nil, destination: 'images', as:nil) @location = location @alt_text = alt_text @width = width @height = height @image_class = image_class @destination = destination @as = as end
Public Instance Methods
compile()
click to toggle source
# File lib/slide_hero/remote_image.rb, line 15 def compile fetch_remote_file unless file_cached? image_class.new(filename, alt_text, width: width, height:height).compile end
Private Instance Methods
fetch_remote_file()
click to toggle source
# File lib/slide_hero/remote_image.rb, line 26 def fetch_remote_file open(location) do |f| File.open("#{destination}/#{filename}","wb") do |file| file.puts f.read end end end
file_cached?()
click to toggle source
# File lib/slide_hero/remote_image.rb, line 22 def file_cached? File.exist?("#{destination}/#{filename}") end
filename()
click to toggle source
# File lib/slide_hero/remote_image.rb, line 34 def filename local_filename || remote_filename end
local_filename()
click to toggle source
# File lib/slide_hero/remote_image.rb, line 38 def local_filename return nil unless as file_extention = URI.parse(location).path.split('.').last "#{as}.#{file_extention}" end
remote_filename()
click to toggle source
# File lib/slide_hero/remote_image.rb, line 44 def remote_filename URI.parse(location).path.split('/').last end