Class: Cul::Image::Properties::Exif::Ratio

Inherits:
Object
  • Object
show all
Defined in:
lib/cul_image_props/image/properties/exif/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#denObject

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

#numObject

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

#inspectObject



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

#reduceObject



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