Class: Officedoc::Package::Raw::PartList

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/officedoc/package/raw/parts.rb

Constant Summary collapse

EntryName =
'[Content_Types].xml'

Instance Method Summary collapse

Constructor Details

#initialize(zip_file) {|_self| ... } ⇒ PartList

Returns a new instance of PartList.

Yields:

  • (_self)

Yield Parameters:



34
35
36
37
38
39
# File 'lib/officedoc/package/raw/parts.rb', line 34

def initialize(zip_file)
  __setobj__([])
  @zip_file = zip_file
  read_from zip_file if zip_file
  yield self if block_given?
end

Instance Method Details

#of_type(type, regexp: false, partial: false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/officedoc/package/raw/parts.rb', line 50

def of_type( type, regexp: false, partial: false )
  select do |part| 
    if regexp 
      part.type.match(type)
    elsif partial
      part.type.include?(type)
    else
      part.type == type
    end
  end
end

#read_from(zip_file) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/officedoc/package/raw/parts.rb', line 41

def read_from(zip_file)
  zip_file.entry_read_stream( EntryName ) do |stream| 
    doc = Nokogiri::XML(stream)
    doc.css("Override[@PartName]").each do |node|
      push Officedoc::Package::Raw::Part.new @zip_file, node
    end
  end
end