Class: CssCompare::CSS::Value::Function

Inherits:
Base
  • Object
show all
Defined in:
lib/css_compare/css/value/function.rb

Overview

Wraps the SassScript Funcall object

Instance Attribute Summary

Attributes inherited from Base

#value

Instance Method Summary collapse

Methods inherited from Base

#equals?, #important?, #initialize, #to_s

Constructor Details

This class inherits a constructor from CssCompare::CSS::Value::Base

Instance Method Details

#==(other) ⇒ Boolean

Checks, whether two function expressions are equal.

Parameters:

  • other (Function)

    the other function expression

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/css_compare/css/value/function.rb', line 11

def ==(other)
  if color?
    return false unless other.color?
    ::Color.equivalent?(color, other.color)
  else
    return false unless super
    arg1 = @value.args.length
    arg2 = other.value.args.length
    return false unless arg1 == arg2
    args1 = @value.args.collect { |x| ValueFactory.create(x) }
    args2 = other.value.args.collect { |x| ValueFactory.create(x) }
    args1.each_index { |i| args1[i] == args2[i] }
  end
end

#alphaObject



45
46
47
48
# File 'lib/css_compare/css/value/function.rb', line 45

def alpha
  return @value.args[3] if alpha?
  false
end

#alpha?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/css_compare/css/value/function.rb', line 41

def alpha?
  @value.args.length == 4
end

#colorObject

Raises:

  • (StandardError)


31
32
33
34
35
36
37
38
39
# File 'lib/css_compare/css/value/function.rb', line 31

def color
  raise StandardError, 'Function not a color' unless color?
  args = @value.args.collect { |x| x.value.value }
  if rgb?
    ::Color::RGB.new(args[0], args[1], args[2])
  elsif hsl?
    ::Color::HSL.new(args[0], args[1], args[2])
  end
end

#color?Boolean

Returns:

  • (Boolean)

See Also:



27
28
29
# File 'lib/css_compare/css/value/function.rb', line 27

def color?
  rgb? || hsl?
end