class Rspreadsheet::XMLTiedItem

@private

If you override intializer make sure you call initialize_xml_tied_item(aparent,aindex).

Optionally you may implement method which makes index accessible under more meaningful name like column or so. Optionally you may implement method which makes parent accessible under more meaningful name like worksheet or so.

By default parent is stored at initialization and never changed. If you do not want to cache it like this (to prevent inconsistencies) just override parent method to dfind the parent dynamically (see Cell). If you do so you may want to disable the default parent handling by calling initialize_xml_tied_item(nil,index) in initializer (or do not call it at all if you have overridden index as well.

Note: If there is a object representing parent (presumably using XMLTiedArray) than initialize signature must be reflected in parent prepare_subitem method

Public Class Methods

new(aparent,aindex) click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 35
def initialize(aparent,aindex)
  initialize_xml_tied_item(aparent,aindex)
end

Public Instance Methods

_shift_by(diff) click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 75
def _shift_by(diff)
  set_index(index + diff)
end
delete() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 102
def delete
  parent.delete_subitem(index)
  invalidate_myself
end
detach() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 70
def detach
  parent.detach_if_needed if parent.respond_to?(:detach_if_needed)
  parent.detach_my_subnode_respect_repeated(index)
  self
end
detach_if_needed() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 67
def detach_if_needed
  detach if repeated? # item did not exist individually yet, detach it within its parent and therefore make it individally editable
end
index() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 39
def index; @xml_tied_item_index end
index=(aindex) click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 41
def index=(aindex); @xml_tied_item_index=aindex end
initialize_xml_tied_item(aparent,aindex) click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 45
def initialize_xml_tied_item(aparent,aindex)
  @xml_tied_parent = aparent unless aparent.nil?
  @xml_tied_item_index = aindex unless aindex.nil?
end
invalid_reference?() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 81
def invalid_reference?; false end
invalidate_myself() click to toggle source

destroys the object so it can not be used, this is necessarry to prevent accessing cells and rows which has been long time ago deleted and do not represent any physical object anymore

# File lib/rspreadsheet/xml_tied_item.rb, line 85
  def invalidate_myself
    raise_destroyed_cell_error = Proc.new {|*params| raise "Calling method of already destroyed Cell."}
    (self.methods - Object.methods + [:nil?]).each do |method| # "undefine" all methods
      self.singleton_class.send(:define_method, method, raise_destroyed_cell_error)
    end
    self.singleton_class.send(:define_method, :inspect, -> { "#<%s:0x%x destroyed cell>" % [self.class,object_id] })  # define descriptive inspect
    if self.singleton_class.respond_to? :remove_method # in ruby 2.5 and higher
      self.singleton_class.remove_method :invalid_reference? if self.singleton_class.method_defined? :invalid_reference?
    end
    self.singleton_class.send(:define_method, :invalid_reference?, -> { true }) # define invalid_reference? method
    # invalidate variables
    @xml_tied_parent=nil
    @xml_tied_item_index=nil
#     self.instance_variables.each do |variable|
#       instance_variable_set(variable,nil)
#     end
  end
is_repeated?()
Alias for: repeated?
mode() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 50
def mode
 case
   when xmlnode.nil? then :outbound
   when repeated>1  then :repeated
   else :regular
 end
end
name_of_repeated_attribute() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 43
def name_of_repeated_attribute; parent.subnode_options[:repeated_attribute] end
parent() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 38
def parent; @xml_tied_parent end
range() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 78
def range
  parent.my_subnode_range(index)
end
repeated() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 57
def repeated; (Tools.get_ns_attribute_value(xmlnode, 'table', name_of_repeated_attribute) || 1 ).to_i end
repeated?() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 58
def repeated?; mode==:repeated || mode==:outbound end
Also aliased as: is_repeated?
set_index(aindex) click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 40
def set_index(aindex); @xml_tied_item_index=aindex end
xmlnode() click to toggle source
# File lib/rspreadsheet/xml_tied_item.rb, line 60
def xmlnode
  if parent.xmlnode.nil?
    nil
  else
    parent.my_subnode(index)
  end
end