Class: PPTXMarkdown::Shape
- Inherits:
-
Struct
- Object
- Struct
- PPTXMarkdown::Shape
- Defined in:
- lib/pptx_markdown/shape.rb
Constant Summary collapse
- TITLE_IDS =
%w(ctrTitle title).freeze
- BODY_IDS =
%w(subTitle body).freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #body? ⇒ Boolean
-
#initialize ⇒ Shape
constructor
A new instance of Shape.
- #title? ⇒ Boolean
- #to_markdown ⇒ Object
-
#to_xml(node) ⇒ String
XML for text shape for ppt/slides/slide0.xml.
Constructor Details
#initialize ⇒ Shape
Returns a new instance of Shape.
9 10 11 12 13 |
# File 'lib/pptx_markdown/shape.rb', line 9 def initialize(*) super raise PPTXMarkdown::TypeError unless (TITLE_IDS + BODY_IDS).include?(type) end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content
5 6 7 |
# File 'lib/pptx_markdown/shape.rb', line 5 def content @content end |
#type ⇒ Object
Returns the value of attribute type
5 6 7 |
# File 'lib/pptx_markdown/shape.rb', line 5 def type @type end |
Instance Method Details
#body? ⇒ Boolean
21 22 23 |
# File 'lib/pptx_markdown/shape.rb', line 21 def body? BODY_IDS.include?(type) end |
#title? ⇒ Boolean
16 17 18 |
# File 'lib/pptx_markdown/shape.rb', line 16 def title? TITLE_IDS.include?(type) end |
#to_markdown ⇒ Object
25 26 27 28 |
# File 'lib/pptx_markdown/shape.rb', line 25 def to_markdown tag = title? ? '* ' : "\t* " format("%s%s\n", tag, content) end |
#to_xml(node) ⇒ String
Returns XML for text shape for ppt/slides/slide0.xml.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pptx_markdown/shape.rb', line 31 def to_xml(node) Nokogiri::XML::Builder.new do |xml| xml.sp(XML_NAMESPACES) do xml.nvSpPr do xml.cNvPr(id: '', name: '') xml.cNvSpPr(txBox: 1) xml.nvPr do xml.ph(idx: nil, type: type) end end xml.spPr do xml['a'].xfrm do xml.off(x: node.x, y: node.y) xml.ext(cx: node.cx, cy: node.cy) end xml['a'].prstGeom(prst: 'rect') do xml.avLst end end xml.txBody do xml['a'].bodyPr(anchorCtr: 0, anchor: 't', bIns: 0, lIns: 0, rIns: 0, tIns: 0) do xml.noAutofit end xml['a'].lstStyle xml['a'].p do xml.pPr(lvl: 0) do xml.spcBef do xml.spcPts(val: 0) end xml.buNone end xml.r do xml.t(content) end end end end end.doc.root.to_xml end |