class MojoMagick::Util::FontParser

Attributes

raw_fonts[R]

Public Class Methods

new(raw_fonts) click to toggle source
# File lib/mojo_magick/util/font_parser.rb, line 7
def initialize(raw_fonts)
  @raw_fonts = raw_fonts
end

Public Instance Methods

parse() click to toggle source
# File lib/mojo_magick/util/font_parser.rb, line 11
def parse
  fonts = {}
  enumerator = raw_fonts.split("\n").each
  name = nil
  while begin; line = enumerator.next; rescue StopIteration; line = nil; end
    line.chomp!
    line = enumerator.next if line_is_empty(line)
    m = /^\s*Font:\s+(.*)$/.match(line)
    if m
      name = m[1].strip
      fonts[name] = { name: name }
    else
      k, v = extract_key_value(line)
      fonts[name][k] = v if k && name
    end
  end
  fonts.values.map { |f| MojoMagick::Font.new f }
end

Private Instance Methods

extract_key_value(line) click to toggle source
# File lib/mojo_magick/util/font_parser.rb, line 32
def extract_key_value(line)
  key_val = line.split(":").map(&:strip)
  [key_val[0].downcase.to_sym, key_val[1]]
end
line_is_empty(line) click to toggle source
# File lib/mojo_magick/util/font_parser.rb, line 37
def line_is_empty(line)
  line.nil? || line.empty? || (/^\s+$/ =~ line)
end