Sha256: c32ebe55d62aa7f6a68b82a6145e6e2b02eb2c19c33abed7a5d047a9d52ac593

Contents?: true

Size: 631 Bytes

Versions: 9

Compression:

Stored size: 631 Bytes

Contents

module Hershey
  class Word
    attr_reader :characters

    def initialize(text, options = {})
      @spacing = 0

      @characters = text.each_char.map do |c|
        char = Character.new(c, options)
        @spacing += char.spacing

        char
      end
    end

    def spacing
      @spacing ||= @characters.inject(0) {|memo, c| memo + c.spacing}
    end

    def to_path(current_offset)
      offset = 0
      letters = []
      @characters.each do |c|
        letters << c.to_path(offset)
        offset += c.spacing
      end

      %Q{<g transform="translate(#{current_offset},0)">#{letters.join}</g>}
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hershey-0.0.11 lib/hershey/word.rb
hershey-0.0.10 lib/hershey/word.rb
hershey-0.0.9 lib/hershey/word.rb
hershey-0.0.8 lib/hershey/word.rb
hershey-0.0.7 lib/hershey/word.rb
hershey-0.0.6 lib/hershey/word.rb
hershey-0.0.5 lib/hershey/word.rb
hershey-0.0.3 lib/hershey/word.rb
hershey-0.0.1 lib/hershey/word.rb