Sha256: 2da5193e2db2df8c55b8236b5fce1d2a8697ba0b0e60eb1e543919f4990afae9
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
# rubocop:disable Lint/AssignmentInCondition module MojoMagick module Util class FontParser attr_reader :raw_fonts def initialize(raw_fonts) @raw_fonts = raw_fonts end 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 def extract_key_value(line) key_val = line.split(/:/).map(&:strip) [key_val[0].downcase.to_sym, key_val[1]] end def line_is_empty(line) line.nil? || line.empty? || (/^\s+$/ =~ line) end end end end # rubocop:enable Lint/AssignmentInCondition
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mojo_magick-0.6.4 | lib/mojo_magick/util/font_parser.rb |
mojo_magick-0.6.3 | lib/mojo_magick/util/font_parser.rb |