lib/css_parser.rb in css_parser-1.6.0 vs lib/css_parser.rb in css_parser-1.7.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
require 'addressable/uri'
require 'uri'
require 'net/https'
require 'digest/md5'
require 'zlib'
@@ -120,14 +121,14 @@
# Thanks to Rafael Salazar and Nick Fitzsimons on the css-discuss list for their help.
#++
def self.calculate_specificity(selector)
a = 0
b = selector.scan(/\#/).length
- c = selector.scan(NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX).length
- d = selector.scan(ELEMENTS_AND_PSEUDO_ELEMENTS_RX).length
+ c = selector.scan(NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX_NC).length
+ d = selector.scan(ELEMENTS_AND_PSEUDO_ELEMENTS_RX_NC).length
- (a.to_s + b.to_s + c.to_s + d.to_s).to_i
+ "#{a}#{b}#{c}#{d}".to_i
rescue
return 0
end
# Make <tt>url()</tt> links absolute.
@@ -158,10 +159,11 @@
"url('#{uri.to_s}')"
end
end
def self.sanitize_media_query(raw)
- mq = raw.to_s.gsub(/[\s]+/, ' ').strip
+ mq = raw.to_s.gsub(/[\s]+/, ' ')
+ mq.strip!
mq = 'all' if mq.empty?
mq.to_sym
end
end