class ImageHelper
Constants
- IMAGE_CLASS_REGEX
- RATING_REGEX
Public Class Methods
color_class(image)
click to toggle source
# File lib/helpers/image_helper.rb, line 14 def self.color_class(image) contents = xmp(image) return if contents.nil? matches = contents.match(IMAGE_CLASS_REGEX) matches[1] if matches end
contains_color_class?(image, values)
click to toggle source
# File lib/helpers/image_helper.rb, line 21 def self.contains_color_class?(image, values) values = [values] unless values.is_a? Array values.include? color_class(image) end
is_5_star?(image)
click to toggle source
# File lib/helpers/image_helper.rb, line 38 def self.is_5_star?(image) rating(image) == '5' end
is_jpeg?(path)
click to toggle source
# File lib/helpers/image_helper.rb, line 42 def self.is_jpeg?(path) # remove . from the beginning extension = File.extname(path)[1..-1] return false if extension.nil? JPEG_EXTENSIONS.include? extension.downcase end
is_select?(image)
click to toggle source
# File lib/helpers/image_helper.rb, line 34 def self.is_select?(image) contains_color_class?(image, SELECT_COLOR_TAGS) || rating(image) >= SELECT_RATING end
rating(image)
click to toggle source
# File lib/helpers/image_helper.rb, line 26 def self.rating(image) contents = xmp(image) return 0 unless contents matches = contents.match(RATING_REGEX) return matches[1].to_i if matches && matches[1].match(/^\d+$/) 0 end
xmp(image)
click to toggle source
identify -format '%[EXIF:*]' .jepg
# File lib/helpers/image_helper.rb, line 8 def self.xmp(image) xmp = File.join(File.dirname(image), File.basename(image, ".*") + ".XMP") return unless File.exist?(xmp) File.read(xmp) end