lib/rspreadsheet/xml_tied.rb in rspreadsheet-0.2.3 vs lib/rspreadsheet/xml_tied.rb in rspreadsheet-0.2.4
- old
+ new
@@ -1,23 +1,25 @@
module Rspreadsheet
+# @private
class XMLTied
def xml
xmlnode.to_s
end
end
+# @private
# abstrac class. All successort MUST implement: set_index,xml_options,parent,index
class XMLTiedItem < XMLTied
def mode
case
when xmlnode.nil? then :outbound
when repeated>1 then :repeated
else :regular
end
end
- def repeated; (Tools.get_ns_attribute_value(xmlnode, 'table', xml_repeated_attribute) || 1 ).to_i end
+ def repeated; (Tools.get_ns_attribute_value(xmlnode, 'table', xml_options[:xml_repeated_attribute]) || 1 ).to_i end
def repeated?; mode==:repeated || mode==:outbound end
alias :is_repeated? :repeated?
def xmlnode
parentnode = parent.xmlnode
if parentnode.nil?
@@ -32,11 +34,11 @@
def detach
parent.detach_if_needed if parent.respond_to?(:detach_if_needed)
parent.detach_my_subnode_respect_repeated(index, xml_options)
self
end
- def shift_by(diff)
+ def _shift_by(diff)
set_index(index + diff)
end
def range
parent.find_my_subnode_range_respect_repeated(index,xml_options)
end
@@ -57,16 +59,18 @@
end
def delete
parent.delete_subitem(index)
invalidate_myself
end
+
end
# abstrac class. All successort MUST implement: prepare_subitem
# terminology
# item, subitem is object from @itemcache (quite often subclass of XMLTiedItem)
# node, subnode is LibXML::XML::Node object
+# @private
module XMLTiedArray
attr_reader :itemcache
def find_my_subnode_range_respect_repeated(aindex, options)
@@ -94,10 +98,18 @@
else
@itemcache[aindex] ||= prepare_subitem(aindex)
end
end
+ def subitems(*params)
+ case params.length
+ when 0 then subitems_array
+ when 1 then subitem(params[0])
+ else raise Exception.new('Wrong number of arguments.')
+ end
+ end
+
def subitems_array
(1..(find_first_unused_index_respect_repeated(subitem_xml_options)-1)).collect do |i|
subitem(i)
end
end
@@ -182,19 +194,16 @@
index = index+repeated
end
return index+1
end
- def insert_subitem_before(aindex)
- insert_subitem_before_with_options(aindex,subitem_xml_options)
- end
- def insert_subitem_before_with_options(aindex,options)
+ def add_empty_subitem_before(aindex)
@itemcache.keys.sort.reverse.select{|i| i>=aindex }.each do |i|
@itemcache[i+1]=@itemcache.delete(i)
- @itemcache[i+1].shift_by(1)
+ @itemcache[i+1]._shift_by(1)
end
- insert_my_subnode_before_respect_repeated(aindex,options) # nyní vlož node do xml
+ insert_my_subnode_before_respect_repeated(aindex,subitem_xml_options) # nyní vlož node do xml
@itemcache[aindex] = subitem(aindex)
end
# clean up item from xml (handle possible detachments) and itemcache. leave the object invalidation on the object
# this should not be called from nowhere but XMLTiedItem.delete
@@ -202,10 +211,10 @@
options = subitem_xml_options
delete_my_subnode_respect_repeated(aindex,options) # vymaž node z xml
@itemcache.delete(aindex)
@itemcache.keys.sort.select{|i| i>=aindex+1 }.each do |i|
@itemcache[i-1]=@itemcache.delete(i)
- @itemcache[i-1].shift_by(-1)
+ @itemcache[i-1]._shift_by(-1)
end
end
def delete
@itemcache.each do |key,item|