Sha256: 7692b7d67b975702fa4b4cac8ab978eefb18647825136cd283faffc574c62467

Contents?: true

Size: 880 Bytes

Versions: 2

Compression:

Stored size: 880 Bytes

Contents

# rubocop:disable Lint/AssignmentInCondition
module MojoMagick
  module Util
    class Parser
      # handle parsing outputs from ImageMagick commands

      def parse_fonts(raw_fonts)
        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.nil? || line.empty? || (/^\s+$/ =~ line)
          m = /^\s*Font:\s+(.*)$/.match(line)
          if m
            name = m[1].strip
            fonts[name] = { name: name }
          else
            key_val = line.split(/:/).map(&:strip)
            k = key_val[0].downcase.to_sym
            v = key_val[1]
            fonts[name][k] = v if k && name
          end
        end
        fonts.values.map { |f| MojoMagick::Font.new f }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mojo_magick-0.6.2 lib/mojo_magick/util/parser.rb
mojo_magick-0.6.0 lib/mojo_magick/util/parser.rb