lib/prawn/icon/parser.rb in prawn-icon-3.0.0 vs lib/prawn/icon/parser.rb in prawn-icon-3.1.0
- old
+ new
@@ -1,7 +1,7 @@
-# encoding: utf-8
-#
+# frozen_string_literal: true
+
# parser.rb: Prawn icon tag text parser (pseudo-HTML).
#
# Copyright October 2014, Jesse Doyle. All rights reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.
@@ -29,19 +29,21 @@
# The font size of a particular icon. If left nil, the
# document's font size will be used.
#
class Parser
PARSER_REGEX = Regexp.new \
- '<icon[^>]*>|</icon>',
- Regexp::IGNORECASE |
- Regexp::MULTILINE
+ '<icon[^>]*>|</icon>',
+ Regexp::IGNORECASE |
+ Regexp::MULTILINE
- CONTENT_REGEX = /<icon[^>]*>(?<content>[^<]*)<\/icon>/mi
+ CONTENT_REGEX = /<icon[^>]*>(?<content>[^<]*)<\/icon>/mi.freeze
- TAG_REGEX = /<icon[^>]*>[^<]*<\/icon>/mi
+ TAG_REGEX = /<icon[^>]*>[^<]*<\/icon>/mi.freeze
- ATTR_REGEX = /(?<attr>[a-zA-Z]*)=["|'](?<val>(\w*[^["|']]))["|']/mi
+ # rubocop:disable Lint/MixedRegexpCaptureTypes
+ ATTR_REGEX = /(?<attr>[a-zA-Z]*)=["|'](?<val>(\w*[^["|']]))["|']/mi.freeze
+ # rubocop:enable Lint/MixedRegexpCaptureTypes
class << self
def format(document, string)
tokens = string.scan(PARSER_REGEX)
config = config_from_tokens(tokens)
@@ -101,22 +103,22 @@
content.each_with_index do |icon, index|
key = Compatibility.new(key: icon).translate
options ||= {}
options = config[index] if config.any?
info = {
- set: FontData.specifier_from_key(key),
- size: options[:size],
- color: options[:color],
+ set: FontData.specifier_from_key(key),
+ size: options[:size],
+ color: options[:color],
content: FontData.unicode_from_key(document, key)
}
icons << info
end
end
end
private
- def attr_hash(value) #:nodoc:
+ def attr_hash(value) # :nodoc:
# If attr == size, we must cast value to float,
# else symbolize the key and map it to value
if value[0] =~ /size/i
{ size: value[1].to_f }
else