Class: Prawn::SVG::Length
- Inherits:
-
Struct
- Object
- Struct
- Prawn::SVG::Length
- Defined in:
- lib/prawn/svg/length.rb,
lib/prawn/svg/length.rb
Constant Summary collapse
- REGEXP =
/\A([+-]?\d*(?:\.\d+)?)(em|rem|ex|px|in|cm|mm|pt|pc)?\z/i.freeze
Instance Attribute Summary collapse
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#unit ⇒ Object
Returns the value of attribute unit
2 3 4 |
# File 'lib/prawn/svg/length.rb', line 2 def unit @unit end |
#value ⇒ Object
Returns the value of attribute value
2 3 4 |
# File 'lib/prawn/svg/length.rb', line 2 def value @value end |
Class Method Details
.parse(value, positive_only: false) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/prawn/svg/length.rb', line 7 def self.parse(value, positive_only: false) if (matches = value.match(REGEXP)) number = Float(matches[1], exception: false) new(number, matches[2]&.downcase&.to_sym) if number && (!positive_only || number >= 0) end end |
Instance Method Details
#to_f ⇒ Object
14 15 16 |
# File 'lib/prawn/svg/length.rb', line 14 def to_f value end |
#to_pixels(_axis_length, font_size) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prawn/svg/length.rb', line 22 def to_pixels(_axis_length, font_size) case unit when :em value * font_size when :rem value * Properties::EM when :ex value * (font_size / 2.0) # we don't have access to the x-height, so this is an approximation approved by the CSS spec when :pc value * 15 # according to http://www.w3.org/TR/SVG11/coords.html when :in value * 72 when :cm value * 10 * (72 / 25.4) when :mm value * (72 / 25.4) else value end end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/prawn/svg/length.rb', line 18 def to_s "#{value}#{unit}" end |