class Languages::Generic::Millimetres
Public Class Methods
new(int)
click to toggle source
# File lib/languages/generic/millimetres.rb, line 4 def initialize(int) @int = int end
Public Instance Methods
+(other)
click to toggle source
# File lib/languages/generic/millimetres.rb, line 12 def +(other) if other.is_a? Millimetres self.class.new(@int + other.to_i) elsif other.is_a? Integer self.class.new(@int + other) else if other.respond_to? :coerce a,b = other.coerce(self) a + b else raise TypeError, "#{other.class} can't be coerced into #{self.class.name}" end end end
-(other)
click to toggle source
# File lib/languages/generic/millimetres.rb, line 27 def -(other) if other.is_a? Millimetres self.class.new(@int - other.to_i) elsif other.is_a? Integer self.class.new(@int - other) else if other.respond_to? :coerce a,b = other.coerce(self) a - b else raise TypeError, "#{other.class} can't be coerced into #{self.class.name}" end end end
==(other)
click to toggle source
# File lib/languages/generic/millimetres.rb, line 42 def ==(other) @int == other.to_i end
coerce(other)
click to toggle source
# File lib/languages/generic/millimetres.rb, line 46 def coerce(other) [Millimetres.new(other),self] end
to_dots(ratio = :dpi203)
click to toggle source
# File lib/languages/generic/millimetres.rb, line 50 def to_dots(ratio = :dpi203) dpm = if ratio == :dpi203 (203/25.4) else (300/25.4) end Languages::Generic::Dots.new((@int * dpm).round) end
to_i()
click to toggle source
# File lib/languages/generic/millimetres.rb, line 8 def to_i @int end