class Prawn::Markup::SizeConverter
Attributes
max[R]
Public Class Methods
new(max)
click to toggle source
# File lib/prawn/markup/support/size_converter.rb, line 8 def initialize(max) @max = max end
Public Instance Methods
convert(string)
click to toggle source
# File lib/prawn/markup/support/size_converter.rb, line 19 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)
click to toggle source
# File lib/prawn/markup/support/size_converter.rb, line 12 def parse(width) return nil if width.to_s.strip.empty? || width.to_s == 'auto' points = convert(width) max ? [points, max].min : points end