class CssCompare::CSS::Value::Base
The base class for wrapping the CSS
property values
Attributes
@return [Sass::Script::Tree::Node]
Public Class Methods
@param [Sass::Script::Tree::Node] value the SassScript value to be wrapped
# File lib/css_compare/css/value/base.rb, line 12 def initialize(value) @value = value end
Public Instance Methods
Checks, whether the CSS
values are equal
@return [Boolean]
# File lib/css_compare/css/value/base.rb, line 19 def ==(other) self.class == other.class end
Checks, whether the CSS
value is a color. Subclasses may override this method.
@return [Boolean]
# File lib/css_compare/css/value/base.rb, line 38 def color? false end
# File lib/css_compare/css/value/base.rb, line 23 def equals?(other) self == other end
Checks, whether the CSS
values are flagged as !important.
@return [Boolean]
# File lib/css_compare/css/value/base.rb, line 30 def important? @value.to_sass.include?('!important') end
@return [String]
# File lib/css_compare/css/value/base.rb, line 43 def to_s @value.to_sass end
Protected Instance Methods
# File lib/css_compare/css/value/base.rb, line 57 def sanitize_font(value) value.gsub(/\\"|"|'/, '') end
Normalizes the quoted string values.
@param [String] value the string to sanitize @return [String] sanitized string
# File lib/css_compare/css/value/base.rb, line 53 def sanitize_string(value) value.sub(/\A['"](.*)['"]\Z/, '\1').gsub(/\\"|"|'/, '"') end
Normalizes the url paths.
We can assume, that a value describes a path if following the removal of leading and trailing quotes it begins with a ‘./`. It can be safely removed without affecting the real value of the CSS
property.
Examples:
"'path/to/file.css'" #=> "path/to/file.css" ""\"path/to/file.css\""" #=> ""path/to/file.css"" "./path/to/file.css" #=> "path/to/file.css"
@param [String] value the url path to normalize @return [String] the normalized path
# File lib/css_compare/css/value/base.rb, line 76 def sanitize_url(value) value = sanitize_string(value) value = value.sub('./', '') if value.start_with?('./') value end