Class: Prawn::SVG::Percentage
- Inherits:
-
Object
- Object
- Prawn::SVG::Percentage
- Defined in:
- lib/prawn/svg/percentage.rb
Constant Summary collapse
- REGEXP =
/\A([+-]?\d*(?:\.\d+)?)%\z/i.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.parse(value, positive_only: false) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/prawn/svg/percentage.rb', line 6 def self.parse(value, positive_only: false) if (matches = value.match(REGEXP)) number = Float(matches[1], exception: false) new(number) if number && (!positive_only || number >= 0) end end |
Instance Method Details
#to_f ⇒ Object
13 14 15 |
# File 'lib/prawn/svg/percentage.rb', line 13 def to_f value end |
#to_factor ⇒ Object
17 18 19 |
# File 'lib/prawn/svg/percentage.rb', line 17 def to_factor value / 100.0 end |
#to_pixels(axis_length, _font_size) ⇒ Object
21 22 23 |
# File 'lib/prawn/svg/percentage.rb', line 21 def to_pixels(axis_length, _font_size) value * axis_length / 100.0 end |