class Hershey::Page

Constants

BUFFER
HEIGHT_STRING
SIDE
SPACE

Public Class Methods

new(width: 1000, height: 1300, stroke: 1) click to toggle source
# File lib/hershey/page.rb, line 8
    def initialize(width: 1000, height: 1300, stroke: 1)
      @close = false
      @height = height
      @width = width
      @current_offset = SIDE
      @line = BUFFER
      @svg = <<-HEADER
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="#{@width}" height="#{HEIGHT_STRING}" version="1.1"
  xmlns="http://www.w3.org/2000/svg" style="stroke-width:#{stroke};">
      HEADER
      @svg << %Q{<g transform="translate(#{SIDE},#{@line})">}
    end

Public Instance Methods

<<(word) click to toggle source
# File lib/hershey/page.rb, line 24
def <<(word)
  if word.is_a?(Word)
    if word.spacing + @current_offset > @width
      new_line
    end
    @svg << word.to_path(@current_offset)
    @current_offset += word.spacing
  elsif word == :space
    @current_offset += SPACE
  elsif word == :break
    new_line
  end
end
Also aliased as: write
svg()
Alias for: write_out
write(word)
Alias for: <<
write_out() click to toggle source
# File lib/hershey/page.rb, line 39
def write_out
  close
  @svg
end
Also aliased as: svg

Private Instance Methods

close() click to toggle source
# File lib/hershey/page.rb, line 58
def close
  unless @close
    @svg << "</g></svg>"
    @svg.gsub!(HEIGHT_STRING, (@line + BUFFER).to_s)
    @close = true
  end
end
new_line() click to toggle source
# File lib/hershey/page.rb, line 47
def new_line
  @line += BUFFER * 2
  if @line > @height
    @line -= BUFFER
    raise PageFullError, "The page is full"
  else
    @current_offset = SIDE
    @svg << %Q{</g><g transform="translate(#{SIDE},#{@line})">}
  end
end