class CssCompare::CSS::Value::Base

The base class for wrapping the CSS property values

Attributes

value[RW]

@return [Sass::Script::Tree::Node]

Public Class Methods

new(value) click to toggle source

@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

==(other) click to toggle source

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
color?() click to toggle source

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
equals?(other) click to toggle source
# File lib/css_compare/css/value/base.rb, line 23
def equals?(other)
  self == other
end
important?() click to toggle source

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
to_s() click to toggle source

@return [String]

# File lib/css_compare/css/value/base.rb, line 43
def to_s
  @value.to_sass
end

Protected Instance Methods

sanitize_font(value) click to toggle source
# File lib/css_compare/css/value/base.rb, line 57
def sanitize_font(value)
  value.gsub(/\\"|"|'/, '')
end
sanitize_string(value) click to toggle source

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
sanitize_url(value) click to toggle source

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