Class: Ballmer::Document::Rels
- Defined in:
- lib/ballmer/document/rels.rb
Overview
CRUD and resolve relative documents to a part. These map to .xml.rel documents in the MS Office document format.
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.from(part) ⇒ Object
Create a Rels class from a given part.
-
.rels_path(part_path) ⇒ Object
Resolve the default rels asset for a given part path.
Instance Method Summary collapse
-
#append(part) ⇒ Object
Append a part to a rel so that we can extract an ID from it, and be really cool like that.
-
#exists?(part) ⇒ Boolean
TODO Check if the part exists.
-
#id(part) ⇒ Object
TODO Returns the rID of the part.
-
#initialize(doc, path, part_path) ⇒ Rels
constructor
TODO - Refactor the part_path business out here.
-
#targets(type) ⇒ Object
Return a list of target paths given a type.
Methods inherited from XMLPart
#commit, #edit_xml, #rels, #xml
Methods inherited from Part
Constructor Details
#initialize(doc, path, part_path) ⇒ Rels
TODO - Refactor the part_path business out here.
9 10 11 12 |
# File 'lib/ballmer/document/rels.rb', line 9 def initialize(doc, path, part_path) super doc, path @part_path = Pathname.new(part_path) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
6 7 8 |
# File 'lib/ballmer/document/rels.rb', line 6 def doc @doc end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/ballmer/document/rels.rb', line 6 def path @path end |
Class Method Details
.from(part) ⇒ Object
Create a Rels class from a given part.
49 50 51 |
# File 'lib/ballmer/document/rels.rb', line 49 def self.from(part) new part.doc, rels_path(part.path), part.path end |
.rels_path(part_path) ⇒ Object
Resolve the default rels asset for a given part path.
54 55 56 |
# File 'lib/ballmer/document/rels.rb', line 54 def self.rels_path(part_path) Pathname.new(part_path).join('../_rels', Pathname.new(part_path).sub_ext('.xml.rels').basename) end |
Instance Method Details
#append(part) ⇒ Object
Append a part to a rel so that we can extract an ID from it, and be really cool like that.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ballmer/document/rels.rb', line 27 def append(part) return nil if exists? part edit_xml do |xml| xml.at_xpath('/xmlns:Relationships').tap do |relationships| relationships << Nokogiri::XML::Node.new("Relationship", xml).tap do |n| n['Id'] = next_id n['Type'] = part.class::REL_TYPE # Rels require a strange path... still haven't quite figured it out but I need to. n['Target'] = rel_path(part) end end end end |
#exists?(part) ⇒ Boolean
TODO Check if the part exists
44 45 46 |
# File 'lib/ballmer/document/rels.rb', line 44 def exists?(part) !! rel(part) end |
#id(part) ⇒ Object
TODO Returns the rID of the part.
21 22 23 |
# File 'lib/ballmer/document/rels.rb', line 21 def id(part) rel(part)['Id'] end |
#targets(type) ⇒ Object
Return a list of target paths given a type.
15 16 17 |
# File 'lib/ballmer/document/rels.rb', line 15 def targets(type) xml.xpath("//xmlns:Relationship[@Type='#{type}']").map{ |n| Pathname.new(n['Target']) } end |