Module: DynamicImage::Ratio
- Defined in:
- lib/dynamic_image/ratio.rb
Overview
DynamicImage Ratio
Coerces an aspect ratio into a float. Strings, rationals, floats and vectors are all accepted.
Class Method Summary collapse
-
.parse(value) ⇒ Float?
Returns the ratio as width divided by height.
Class Method Details
.parse(value) ⇒ Float?
Returns the ratio as width divided by height.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dynamic_image/ratio.rb', line 21 def parse(value) return if value.nil? ratio = coerce(value) unless ratio.is_a?(Float) && ratio.positive? && ratio.finite? raise ArgumentError, "invalid ratio: #{value.inspect}" end ratio end |