Class: Sass::Value::Calculation

Inherits:
Object
  • Object
show all
Includes:
CalculationValue, Sass::Value
Defined in:
lib/sass/value/calculation.rb

Overview

Sass’s calculation type.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CalculationValue

#assert_calculation_value

Methods included from Sass::Value

#[], #assert_boolean, #assert_calculation_value, #assert_color, #assert_function, #assert_map, #assert_number, #assert_string, #at, #bracketed?, #eql?, #sass_index_to_array_index, #separator, #to_a, #to_bool, #to_map, #to_nil

Constructor Details

#initialize(name, arguments) ⇒ Calculation

Returns a new instance of Calculation.



12
13
14
15
# File 'lib/sass/value/calculation.rb', line 12

def initialize(name, arguments)
  @name = name.freeze
  @arguments = arguments.freeze
end

Instance Attribute Details

#argumentsArray<CalculationValue> (readonly)

Returns:



21
22
23
# File 'lib/sass/value/calculation.rb', line 21

def arguments
  @arguments
end

#name::String (readonly)

Returns:

  • (::String)


18
19
20
# File 'lib/sass/value/calculation.rb', line 18

def name
  @name
end

Class Method Details

.calc(argument) ⇒ Calculation

Parameters:

Returns:



28
29
30
31
# File 'lib/sass/value/calculation.rb', line 28

def calc(argument)
  argument.assert_calculation_value
  new('calc', [argument])
end

.clamp(min, value = nil, max = nil) ⇒ Calculation

Parameters:

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sass/value/calculation.rb', line 51

def clamp(min, value = nil, max = nil)
  if (value.nil? && !valid_clamp_arg?(min)) ||
     (max.nil? && [min, value].none? { |x| x && valid_clamp_arg?(x) })
    raise Sass::ScriptError, 'Argument must be an unquoted SassString or CalculationInterpolation.'
  end

  arguments = [min]
  arguments.push(value) unless value.nil?
  arguments.push(max) unless max.nil?
  arguments.each(&:assert_calculation_value)
  new('clamp', arguments)
end

.max(arguments) ⇒ Calculation

Parameters:

Returns:



42
43
44
45
# File 'lib/sass/value/calculation.rb', line 42

def max(arguments)
  arguments.each(&:assert_calculation_value)
  new('max', arguments)
end

.min(arguments) ⇒ Calculation

Parameters:

Returns:



35
36
37
38
# File 'lib/sass/value/calculation.rb', line 35

def min(arguments)
  arguments.each(&:assert_calculation_value)
  new('min', arguments)
end

Instance Method Details

#==(other) ⇒ ::Boolean

Returns:

  • (::Boolean)


78
79
80
81
82
# File 'lib/sass/value/calculation.rb', line 78

def ==(other)
  other.is_a?(Sass::Value::Calculation) &&
    other.name == name &&
    other.arguments == arguments
end

#assert_calculation(_name = nil) ⇒ Calculation

Returns:



73
74
75
# File 'lib/sass/value/calculation.rb', line 73

def assert_calculation(_name = nil)
  self
end

#hashInteger

Returns:

  • (Integer)


85
86
87
# File 'lib/sass/value/calculation.rb', line 85

def hash
  @hash ||= [name, *arguments].hash
end