class Thinreports::Core::Shape::Manager::Internal

Attributes

format[R]
lists[R]
shapes[R]

Public Class Methods

new(format, init_item_handler) click to toggle source

@param [Thinreports::Core::Manager::Format] format @param [Proc] init_item_handler

# File lib/thinreports/core/shape/manager/internal.rb, line 16
def initialize(format, init_item_handler)
  @format = format
  @shapes = {}
  @lists = {}
  @init_item_handler = init_item_handler
end

Public Instance Methods

final_shape(id) click to toggle source

@param [String, Symbol] id @return [Thinreports::Core::Shape::Base::Interface, nil]

# File lib/thinreports/core/shape/manager/internal.rb, line 50
def final_shape(id)
  shape = shapes[id]

  # When shape was found in registry.
  if shape
    return nil unless shape.visible?

    # In the case of TextBlock or ImageBlock.
    if shape.internal.type_of?(:block)
      blank_value?(shape.internal.real_value) ? nil : shape
    else
      shape
    end
  # When shape was not found in registry.
  elsif format.has_shape?(id)
    shape_format = find_format(id)
    return nil unless shape_format.display?

    case shape_format.type
    # In the case of TextBlock.
    when TextBlock::TYPE_NAME
      return nil if !shape_format.has_reference? && blank_value?(shape_format.value)
      init_item(shape_format)
    # In the case of ImageBlock, Return the nil constantly.
    when ImageBlock::TYPE_NAME
      nil
    else
      init_item(shape_format)
    end
  end
end
find_format(id) click to toggle source

@param [String, Symbol] id @return [Thinreports::Core::Shape::Basic::Format]

# File lib/thinreports/core/shape/manager/internal.rb, line 25
def find_format(id)
  format.find_shape(id.to_sym)
end
find_item(id, limit = {}) click to toggle source

@param [String, Symbol] id @param limit (see valid_type?)

# File lib/thinreports/core/shape/manager/internal.rb, line 31
def find_item(id, limit = {})
  id = id.to_sym

  if shapes.key?(id)
    shape = shapes[id]
    valid_type?(shape.type, limit) ? shape : nil
  elsif find_format(id)
    shape_format = find_format(id)
    return nil unless valid_type?(shape_format.type, limit)

    shape = init_item(shape_format)
    shapes[id] = shape

    shape
  end
end
init_item(format) click to toggle source

@param [Thinreports::Core::Shape::Basic::Format] format

# File lib/thinreports/core/shape/manager/internal.rb, line 83
def init_item(format)
  @init_item_handler.call(format)
end
valid_type?(type, limit = {}) click to toggle source

@param [String] type @param [Hash] limit @option limit [String] :only @option limit [String] :except @return [Booldan]

# File lib/thinreports/core/shape/manager/internal.rb, line 92
def valid_type?(type, limit = {})
  return true if limit.empty?

  if limit[:only]
    type == limit[:only]
  elsif limit[:except]
    type != limit[:except]
  else
    raise ArgumentError
  end
end