Class: Xsdvi::Utils::WidthCalculator
- Inherits:
-
Object
- Object
- Xsdvi::Utils::WidthCalculator
- Defined in:
- lib/xsdvi/utils/width_calculator.rb
Overview
Calculates width for SVG elements based on text content
Instance Attribute Summary collapse
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(min_width) ⇒ WidthCalculator
constructor
A new instance of WidthCalculator.
- #new_width(char_width, text, additional = 0) ⇒ Object
Constructor Details
#initialize(min_width) ⇒ WidthCalculator
Returns a new instance of WidthCalculator.
9 10 11 |
# File 'lib/xsdvi/utils/width_calculator.rb', line 9 def initialize(min_width) @width = min_width end |
Instance Attribute Details
#width ⇒ Object (readonly)
Returns the value of attribute width.
7 8 9 |
# File 'lib/xsdvi/utils/width_calculator.rb', line 7 def width @width end |
Instance Method Details
#new_width(char_width, text, additional = 0) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/xsdvi/utils/width_calculator.rb', line 13 def new_width(char_width, text, additional = 0) return unless text text_length = text.is_a?(String) ? text.length : text calculated_width = char_width + (text_length * 6) + additional @width = calculated_width if calculated_width > @width end |