diff options
| author | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
| commit | e53f04284618713b0a90b7a691425c380e829476 (patch) | |
| tree | 801fea138160f9af426d62bf94ad5bf97123ece9 /lib/axlsx/rels | |
| download | caxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip | |
first commit
Diffstat (limited to 'lib/axlsx/rels')
| -rw-r--r-- | lib/axlsx/rels/relationship.rb | 43 | ||||
| -rw-r--r-- | lib/axlsx/rels/relationships.rb | 25 |
2 files changed, 68 insertions, 0 deletions
diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb new file mode 100644 index 00000000..57b9afc0 --- /dev/null +++ b/lib/axlsx/rels/relationship.rb @@ -0,0 +1,43 @@ +module Axlsx + # A relationship defines a reference between package parts. + # @note Packages automatcially manage relationships. + class Relationship + + # The location of the relationship target + # @return [String] + attr_accessor :Target + + # The type of relationship + # @note Supported types are defined as constants in Axlsx: + # @see XML_NS_R + # @see TABLE_R + # @see WORKBOOK_R + # @see WORKSHEET_R + # @see APP_R + # @see RELS_R + # @see CORE_R + # @see STYLES_R + # @see CHART_R + # @see DRAWING_R + # @return [String] + attr_accessor :Type + def initialize(type, target) + self.Target=target + self.Type=type + end + + def Target=(v) Axlsx::validate_string v; @Target = v end + def Type=(v) Axlsx::validate_relationship_type v; @Type = v end + + # Serializes the relationship + # TODO: use object.rId to get this infomation + # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. + # @param [String] rId the reference id of the object. + # @return [String] + def to_xml(xml, rId) + h = self.instance_values + h[:Id] = rId + xml.Relationship(h) + end + end +end diff --git a/lib/axlsx/rels/relationships.rb b/lib/axlsx/rels/relationships.rb new file mode 100644 index 00000000..9ee334a5 --- /dev/null +++ b/lib/axlsx/rels/relationships.rb @@ -0,0 +1,25 @@ +module Axlsx +require 'axlsx/rels/relationship.rb' + + # Relationships are a collection of Relations that define how package parts are related. + # @note The package automatically manages releationships. + class Relationships < SimpleTypedList + + # Creates a new Relationships collection based on SimpleTypedList + def initialize + super Relationship + end + + # Serializes the relationships document. + # @return [String] + def to_xml() + builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| + xml.Relationships(:xmlns => Axlsx::RELS_R) { + each_with_index { |rel, index| rel.to_xml(xml, "rId#{index+1}") } + } + end + builder.to_xml + end + + end +end |
