Class: Layouter::Leaf::Annotation
- Defined in:
- lib/layouter/leaf/annotation.rb
Constant Summary collapse
- ALMOST =
"~"- ELLIPSIS =
"\u2026"
Constants inherited from Base
Instance Attribute Summary collapse
-
#max_height ⇒ Object
Returns the value of attribute max_height.
-
#min_height ⇒ Object
Returns the value of attribute min_height.
Attributes inherited from Base
Attributes inherited from Element
#calculated_height, #calculated_width
Instance Method Summary collapse
-
#initialize(content, importance: 1, trim: true) ⇒ Annotation
constructor
A new instance of Annotation.
- #max_width ⇒ Object
- #min_width ⇒ Object
- #render ⇒ Object
Methods inherited from Base
Methods inherited from Element
Constructor Details
#initialize(content, importance: 1, trim: true) ⇒ Annotation
Returns a new instance of Annotation.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/layouter/leaf/annotation.rb', line 10 def initialize(content, importance: 1, trim: true) super(importance: importance) unless content.is_a?(Numeric) || content.is_a?(String) raise(ArgumentError, "Must be a number or strings") end @content = content @trim = trim @min_width = @max_width = @content.to_s.length # TODO: make smarter. @min_height = @max_height = 1 end |
Instance Attribute Details
#max_height ⇒ Object
Returns the value of attribute max_height.
8 9 10 |
# File 'lib/layouter/leaf/annotation.rb', line 8 def max_height @max_height end |
#min_height ⇒ Object
Returns the value of attribute min_height.
8 9 10 |
# File 'lib/layouter/leaf/annotation.rb', line 8 def min_height @min_height end |
Instance Method Details
#max_width ⇒ Object
32 33 34 |
# File 'lib/layouter/leaf/annotation.rb', line 32 def max_width @content.to_s.length end |
#min_width ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/layouter/leaf/annotation.rb', line 21 def min_width if @trim && @content.is_a?(String) 2 elsif @trim && @content.is_a?(Numeric) dot = @content.to_s.index(".") dot ? dot + 1 : @content.to_s.length else @content.to_s.length end end |
#render ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/layouter/leaf/annotation.rb', line 36 def render layout! if @calculated_width == @content.to_s.length @content.to_s elsif @content.is_a?(String) @content[0...(@calculated_width - 1)] + ELLIPSIS elsif @content.is_a?(Numeric) ALMOST + @content.to_s[0...(@calculated_width - 1)] end end |