class Layouter::Leaf::Annotation

Constants

ALMOST
ELLIPSIS

Attributes

max_height[RW]
min_height[RW]

Public Class Methods

new(content, importance: 1, trim: true) click to toggle source
Calls superclass method
# 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

Public Instance Methods

max_width() click to toggle source
# File lib/layouter/leaf/annotation.rb, line 32
def max_width
  @content.to_s.length
end
min_width() click to toggle source
# 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() click to toggle source
# 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