class Hershey::Document
Constants
- BUFFER
- HEIGHT_STRING
- SIDE
Public Class Methods
new(width: 1000, height: 1300, spacing: 3, vertical: 20, font: :futural, stroke: 1)
click to toggle source
# File lib/hershey/document.rb, line 7 def initialize(width: 1000, height: 1300, spacing: 3, vertical: 20, font: :futural, stroke: 1) @words = [] @pages = [] @width = width @height = height @spacing = spacing @line = BUFFER @vertical = vertical @closed = false @font = font @stroke = stroke end
Public Instance Methods
<<(text)
click to toggle source
# File lib/hershey/document.rb, line 28 def <<(text) word = "" text.each_char do |c| if c == " " @words << Word.new(word, font: @font) word = '' @words << :space elsif c == "\n" @words << Word.new(word, font: @font) word = '' @words << :break else word << c end end @words << Word.new(word, font: @font) unless word == '' end
Also aliased as: write
[](page)
click to toggle source
# File lib/hershey/document.rb, line 20 def [](page) @pages[page].svg end
length()
click to toggle source
# File lib/hershey/document.rb, line 24 def length @pages.length end
svg()
click to toggle source
# File lib/hershey/document.rb, line 48 def svg write_out unless @closed self[0] end
svgs()
click to toggle source
# File lib/hershey/document.rb, line 53 def svgs write_out unless @closed @pages.map {|page| page.svg} end
Private Instance Methods
new_page()
click to toggle source
# File lib/hershey/document.rb, line 73 def new_page @pages << Page.new(width: @width, height: @height, stroke: @stroke) end
write_out()
click to toggle source
# File lib/hershey/document.rb, line 60 def write_out new_page @words.each do |word| begin @pages.last.write(word) rescue PageFullError puts "Page # #{@pages.length}" new_page retry end end end