Class: Goldendocx::Documents::Body
- Inherits:
-
Object
- Object
- Goldendocx::Documents::Body
- Includes:
- Element
- Defined in:
- lib/goldendocx/documents/body.rb
Constant Summary collapse
- XML_PATH =
'word/document.xml'
Instance Attribute Summary collapse
-
#charts ⇒ Object
readonly
Returns the value of attribute charts.
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Class Method Summary collapse
Instance Method Summary collapse
- #create_chart(chart_type, chart_id, relationship_id, options) ⇒ Object
- #create_embed_image(relationship_id, options) ⇒ Object
- #create_image(relationship_id, options) ⇒ Object
- #create_table(options = {}) ⇒ Object
- #create_text(text, options = {}) ⇒ Object
- #ensure_chart_type(chart_type) ⇒ Object
-
#initialize ⇒ Body
constructor
A new instance of Body.
-
#to_element(**_context) ⇒ Object
FIXME: Override for children not in correctly order.
Methods included from Element
#build_element, #namespace, #tag, #tag_name, #to_xml
Methods included from HasChildren
#children, #read_child, #read_children
Methods included from HasAttributes
#assign_attributes, #attributes, #read_attributes
Constructor Details
#initialize ⇒ Body
Returns a new instance of Body.
36 37 38 39 |
# File 'lib/goldendocx/documents/body.rb', line 36 def initialize @components = [] @charts = [] end |
Instance Attribute Details
#charts ⇒ Object (readonly)
Returns the value of attribute charts.
10 11 12 |
# File 'lib/goldendocx/documents/body.rb', line 10 def charts @charts end |
#components ⇒ Object (readonly)
Returns the value of attribute components.
10 11 12 |
# File 'lib/goldendocx/documents/body.rb', line 10 def components @components end |
Class Method Details
.read_from(xml_node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/goldendocx/documents/body.rb', line 24 def read_from(xml_node) document = super(xml_node) = %w[w:p w:tbl] xml_node.children.map do |node| document.components << node if .include?(node.tag_name) end document end |
Instance Method Details
#create_chart(chart_type, chart_id, relationship_id, options) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/goldendocx/documents/body.rb', line 87 def create_chart(chart_type, chart_id, relationship_id, ) chart_class = ensure_chart_type(chart_type) chart = chart_class.new(chart_id, relationship_id, ) charts << chart components << chart chart end |
#create_embed_image(relationship_id, options) ⇒ Object
76 77 78 |
# File 'lib/goldendocx/documents/body.rb', line 76 def (relationship_id, ) Goldendocx::Components::Image.new(relationship_id:, width: [:width], height: [:height]) end |
#create_image(relationship_id, options) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/goldendocx/documents/body.rb', line 68 def create_image(relationship_id, ) image = build_image(relationship_id:, width: [:width], height: [:height]) components << image image end |
#create_table(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/goldendocx/documents/body.rb', line 59 def create_table( = {}) table = build_table table.width = [:width] if [:width] components << table table end |
#create_text(text, options = {}) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/goldendocx/documents/body.rb', line 51 def create_text(text, = {}) text = build_text(text:, **.slice(:align, :color, :bold)) components << text text end |
#ensure_chart_type(chart_type) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/goldendocx/documents/body.rb', line 80 def ensure_chart_type(chart_type) chart_class = "::Goldendocx::Components::#{chart_type.capitalize}Chart" raise Goldendocx::Charts::InvalidChartType unless Kernel.const_defined?(chart_class) Kernel.const_get(chart_class) end |
#to_element(**_context) ⇒ Object
FIXME: Override for children not in correctly order
42 43 44 45 46 47 48 49 |
# File 'lib/goldendocx/documents/body.rb', line 42 def to_element(**_context) Goldendocx.xml_serializer.build_element(tag_name) do |xml| components.each { |component| xml << component } xml << section_property if section_property yield(xml) if block_given? end end |