Class: ImageHelper
- Inherits:
-
Object
- Object
- ImageHelper
- Defined in:
- lib/helpers/image_helper.rb
Constant Summary collapse
- IMAGE_CLASS_REGEX =
/xmp:Label="(.+)"/
- RATING_REGEX =
/xmp:Rating="(.+)"/
Class Method Summary collapse
- .color_class(image) ⇒ Object
- .contains_color_class?(image, values) ⇒ Boolean
- .is_5_star?(image) ⇒ Boolean
- .is_jpeg?(path) ⇒ Boolean
- .is_select?(image) ⇒ Boolean
- .rating(image) ⇒ Object
-
.xmp(image) ⇒ Object
identify -format ‘%[EXIF:*]’ .jepg.
Class Method Details
.color_class(image) ⇒ Object
14 15 16 17 18 19 |
# 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) ⇒ Boolean
21 22 23 24 |
# 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) ⇒ Boolean
38 39 40 |
# File 'lib/helpers/image_helper.rb', line 38 def self.is_5_star?(image) (image) == '5' end |
.is_jpeg?(path) ⇒ Boolean
42 43 44 45 46 47 |
# 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) ⇒ Boolean
34 35 36 |
# File 'lib/helpers/image_helper.rb', line 34 def self.is_select?(image) contains_color_class?(image, SELECT_COLOR_TAGS) || (image) >= SELECT_RATING end |
.rating(image) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/helpers/image_helper.rb', line 26 def self.(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 |