class Prawn::Markup::Builders::NestableBuilder

Constants

TEXT_STYLE_OPTIONS

Attributes

options[R]
pdf[R]
total_width[R]

Public Class Methods

new(pdf, total_width, options = {}) click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 11
def initialize(pdf, total_width, options = {})
  @pdf = pdf
  @total_width = total_width
  @options = options
end

Private Instance Methods

compute_image_width(hash, max_width) click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 33
def compute_image_width(hash, max_width)
  hash.dup.tap do |image_hash|
    image_hash.delete(:width)
    image_hash[:image_width] = SizeConverter.new(max_width).parse(hash[:width])
    if max_width
      natural_width, _height = natural_image_dimensions(image_hash)
      image_hash[:fit] = [max_width, 999_999] if max_width < natural_width
    end
  end
end
convert_style_options(hash) click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 55
def convert_style_options(hash)
  hash[:font_style] ||= hash.delete(:style)
  hash[:text_color] ||= hash.delete(:color)
end
extract_text_cell_style(hash) click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 49
def extract_text_cell_style(hash)
  TEXT_STYLE_OPTIONS
    .each_with_object({}) { |key, h| h[key] = hash[key] }
    .tap { |options| convert_style_options(options) }
end
natural_image_dimensions(hash) click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 44
def natural_image_dimensions(hash)
  _obj, info = pdf.build_image_object(hash[:image])
  info.calc_image_dimensions(width: hash[:image_width])
end
normalize_cell_hash(hash, cell_width, style_options = {}) click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 21
def normalize_cell_hash(hash, cell_width, style_options = {})
  if hash.key?(:image)
    compute_image_width(hash, cell_width)
  else
    style_options.merge(hash)
  end
end
text_options() click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 29
def text_options
  (options[:text] || {})
end
type_key(object) click to toggle source
# File lib/prawn/markup/builders/nestable_builder.rb, line 60
def type_key(object)
  path = object.class.name.to_s
  i = path.rindex('::')
  if i
    path[(i + 2)..-1].downcase
  else
    path.downcase
  end
end