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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num, den) ⇒ Ratio

Returns a new instance of Ratio.



72
73
74
75
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 72

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



61
62
63
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 61

def den
  @den
end

#numObject

ratio object that eventually will be able to reduce itself to lowest common denominator for printing



61
62
63
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 61

def num
  @num
end

Class Method Details

.gcd(a, b) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 62

def self.gcd(a, b)
    if b == 1 or a == 1
        return 1
    elsif b == 0
        return a
    else
        return gcd(b, a % b)
    end
end

Instance Method Details

#inspectObject



77
78
79
80
81
82
83
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 77

def inspect
    self.reduce()
    if @den == 1
        return self.num.to_s
    end
    return format("%d/%d", @num, @den)
end

#reduceObject



85
86
87
88
89
90
91
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 85

def reduce
    div = Ratio.gcd(@num, @den)
    if div > 1
        @num = @num / div
        @den = @den / div
    end
end