class Ires::Service
Public Class Methods
path(path, width: nil, height: nil, type: Type::ALL, mode: Mode::RESIZE, expire: 30.days)
click to toggle source
Resize image path @return [String]
# File lib/ires/service.rb, line 11 def path(path, width: nil, height: nil, type: Type::ALL, mode: Mode::RESIZE, expire: 30.days) raise StandardError, "#{path} is not string." unless path.kind_of?(String) raise ArgumentError, "Either width or height is required." if width.nil? && height.nil? os = Ires::Os.current return nil if os.nil? raise StandardError, "Nil location provided. Can't build URI." if path.nil? return path if path.empty? full_path = image_full_path(path.to_s) # if no image or could not find file path then perform the same action as 'image_tag' return nil if invalid_path?(full_path) expiration_date = expiration_date(expire) dir = image_dir ires_element = { path: full_path, width: width || 0, height: height || 0, mode: mode, type: type, dir: dir, expire: expiration_date } ires_image_path(ires_element) end
Private Class Methods
expiration_date(expire)
click to toggle source
Expiration date (default: 7.days) ex. “20170101” @return [String]
# File lib/ires/service.rb, line 68 def expiration_date(expire) (Time.zone.today + expire).strftime('%Y%m%d') end
image_dir()
click to toggle source
Reszie image directory @return [String]
# File lib/ires/service.rb, line 55 def image_dir @image_dir ||= Pathname.new(Rails.root).join('public').to_s end
image_full_path(path)
click to toggle source
Image full path or HTTP URL @return [String]
# File lib/ires/service.rb, line 44 def image_full_path(path) root = Rails.root.to_s if path.include?(root) || path.include?('http') path else File.join(image_dir, path) end end
invalid_path?(path)
click to toggle source
Check file or URI @return [Bool]
# File lib/ires/service.rb, line 61 def invalid_path?(path) !File.exist?(path) && !path.include?('http') end
ires_image_path(ires_element)
click to toggle source
Image path @return [String]
# File lib/ires/service.rb, line 74 def ires_image_path(ires_element) mode = ires_element[:mode] ires_element.delete(:mode) case mode when Mode::RESIZE Core.resizeImagePath(*ires_element.values) when Mode::CROP Core.cropImagePath(*ires_element.values) when Mode::RESIZE_TO_CROP Core.resizeToCropImagePath(*ires_element.values) else Core.resizeImagePath(*ires_element.values) end end