Class: Cul::Image::Properties::Exif::Ratio
- Inherits:
-
Object
- Object
- Cul::Image::Properties::Exif::Ratio
- Defined in:
- lib/cul_image_props/image/properties/exif/types.rb
Instance Attribute Summary collapse
-
#den ⇒ Object
ratio object that eventually will be able to reduce itself to lowest common denominator for printing.
-
#num ⇒ Object
ratio object that eventually will be able to reduce itself to lowest common denominator for printing.
Instance Method Summary collapse
- #gcd(a, b) ⇒ Object
-
#initialize(num, den) ⇒ Ratio
constructor
A new instance of Ratio.
- #inspect ⇒ Object
- #reduce ⇒ Object
Constructor Details
#initialize(num, den) ⇒ Ratio
Returns a new instance of Ratio.
51 52 53 54 |
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 51 def initialize(num, den) @num = num @den = den end |
Instance Attribute Details
#den ⇒ Object
ratio object that eventually will be able to reduce itself to lowest common denominator for printing
40 41 42 |
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 40 def den @den end |
#num ⇒ Object
ratio object that eventually will be able to reduce itself to lowest common denominator for printing
40 41 42 |
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 40 def num @num end |
Instance Method Details
#gcd(a, b) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 41 def gcd(a, b) if b == 1 or a == 1 return 1 elsif b == 0 return a else return gcd(b, a % b) end end |
#inspect ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 56 def inspect self.reduce() if @den == 1 return self.num.to_s end return format("%d/%d", @num, @den) end |
#reduce ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 64 def reduce div = gcd(@num, @den) if div > 1 @num = @num / div @den = @den / div end end |