Class: Typst::Document
- Inherits:
-
Object
- Object
- Typst::Document
- Defined in:
- lib/document.rb
Direct Known Subclasses
HtmlDocument, HtmlExperimentalDocument, PdfDocument, PngDocument, SvgDocument
Instance Attribute Summary collapse
-
#bytes ⇒ Object
Returns the value of attribute bytes.
Instance Method Summary collapse
- #document ⇒ Object
-
#initialize(bytes) ⇒ Document
constructor
A new instance of Document.
- #pages ⇒ Object
- #write(out) ⇒ Object
Constructor Details
#initialize(bytes) ⇒ Document
Returns a new instance of Document.
5 6 7 |
# File 'lib/document.rb', line 5 def initialize(bytes) @bytes = bytes end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
3 4 5 |
# File 'lib/document.rb', line 3 def bytes @bytes end |
Instance Method Details
#document ⇒ Object
25 26 27 |
# File 'lib/document.rb', line 25 def document pages.size == 1 ? pages.first : pages end |
#pages ⇒ Object
21 22 23 |
# File 'lib/document.rb', line 21 def pages bytes.collect{ |page| page.pack("C*").to_s } end |
#write(out) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/document.rb', line 9 def write(out) if pages.size == 1 File.write(out, pages.first, mode: "wb") else pages.each_with_index do |page, i| fn = File.basename(out, ".*") + "_{{n}}" + File.extname(out) unless out.include?("{{n}}") fn = fn.gsub("{{n}}", (i+1).to_s) File.write(fn, page, mode: "wb") end end end |