Class: Inkmake::InkscapeUnit
- Inherits:
-
Object
- Object
- Inkmake::InkscapeUnit
- Defined in:
- lib/inkmake.rb
Constant Summary collapse
- Units =
90dpi as reference
{ "pt" => 1.25, "pc" => 15, "mm" => 3.543307, "cm" => 35.43307, "dm" => 354.3307, "m" => 3543.307, "in" => 90, "ft" => 1080, "uu" => 1 # user unit, 90 dpi }
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, unit = "uu") ⇒ InkscapeUnit
constructor
A new instance of InkscapeUnit.
- #scale(f) ⇒ Object
- #to_pixels(dpi = 90.0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value, unit = "uu") ⇒ InkscapeUnit
Returns a new instance of InkscapeUnit.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/inkmake.rb', line 70 def initialize(value, unit="uu") case value when /^(\d+(?:\.\d+)?)(\w+)?$/ then @value = $1.to_f @unit = $2 @unit ||= unit @unit = (@unit == "px" or Units.has_key?(@unit)) ? @unit : "uu" else @value = value.kind_of?(String) ? value.to_f: value @unit = unit end end |
Instance Attribute Details
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
68 69 70 |
# File 'lib/inkmake.rb', line 68 def unit @unit end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
68 69 70 |
# File 'lib/inkmake.rb', line 68 def value @value end |
Instance Method Details
#scale(f) ⇒ Object
92 93 94 95 |
# File 'lib/inkmake.rb', line 92 def scale(f) return self if @unit == "px" InkscapeUnit.new(@value * f, @unit) end |
#to_pixels(dpi = 90.0) ⇒ Object
83 84 85 86 |
# File 'lib/inkmake.rb', line 83 def to_pixels(dpi=90.0) return @value.round if @unit == "px" ((dpi / 90.0) * Units[@unit] * @value).round end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/inkmake.rb', line 88 def to_s "%g#{@unit}" % @value end |