Class: RiotCarrierwave::HasDimensionsAssertion

Inherits:
Riot::AssertionMacro
  • Object
show all
Defined in:
lib/riot-carrierwave/has_dimensions.rb

Instance Method Summary collapse

Instance Method Details

#compare(type, image, width, height) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/riot-carrierwave/has_dimensions.rb', line 14

def compare(type, image, width,height)
  case type
  when :no_larger_than
    width >= image.width and height >= image.height
  when :no_smaller_than
    width <= image.width and height <= image.height
  when :larger_than
    width < image.width and height < image.height
  when :smaller_than
    width > image.width and height > image.height
  when :equal
    width == image.width and height == image.height
  else
    false
  end
end

#evaluate(model, type, width, height) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/riot-carrierwave/has_dimensions.rb', line 5

def evaluate(model, type, width, height)
  image = RiotCarrierwave::ImageLoader.load_image(model.current_path)
  if image and compare(type, image, width, height)
    pass "#{model.class.name} has dimensions #{type} width #{width}px and height #{height}px"
  else
    fail "expected #{model.class.name} to have dimensions #{type} width #{width}px and height #{height}px"
  end
end