Class: Prawn::Markup::SizeConverter
- Inherits:
-
Object
- Object
- Prawn::Markup::SizeConverter
- Defined in:
- lib/prawn/markup/support/size_converter.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
Instance Method Summary collapse
- #convert(string) ⇒ Object
-
#initialize(max) ⇒ SizeConverter
constructor
A new instance of SizeConverter.
- #parse(width) ⇒ Object
Constructor Details
#initialize(max) ⇒ SizeConverter
Returns a new instance of SizeConverter.
6 7 8 |
# File 'lib/prawn/markup/support/size_converter.rb', line 6 def initialize(max) @max = max end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
4 5 6 |
# File 'lib/prawn/markup/support/size_converter.rb', line 4 def max @max end |
Instance Method Details
#convert(string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/prawn/markup/support/size_converter.rb', line 17 def convert(string) value = string.to_f if string.end_with?('%') value * max / 100.0 elsif string.end_with?('cm') value.cm elsif string.end_with?('mm') value.mm else value end end |
#parse(width) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/prawn/markup/support/size_converter.rb', line 10 def parse(width) return nil if width.to_s.strip.empty? || width.to_s == 'auto' points = convert(width) max ? [points, max].min : points end |