Class: SimpleSelector::Specificity

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/simple_selector/specificity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a = 0, b = 0, c = 0, d = 0) ⇒ Specificity

Returns a new instance of Specificity.



6
7
8
# File 'lib/simple_selector/specificity.rb', line 6

def initialize(a=0, b=0, c=0, d=0)
  @a, @b, @c, @d = a, b, c, d
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



10
11
12
# File 'lib/simple_selector/specificity.rb', line 10

def a
  @a
end

#bObject

Returns the value of attribute b.



10
11
12
# File 'lib/simple_selector/specificity.rb', line 10

def b
  @b
end

#cObject

Returns the value of attribute c.



10
11
12
# File 'lib/simple_selector/specificity.rb', line 10

def c
  @c
end

#dObject

Returns the value of attribute d.



10
11
12
# File 'lib/simple_selector/specificity.rb', line 10

def d
  @d
end

Instance Method Details

#+(other) ⇒ Object



20
21
22
# File 'lib/simple_selector/specificity.rb', line 20

def +(other)
  self.class.new(a + other.a, b + other.b, c + other.c, d + other.d)
end

#<=>(other) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/simple_selector/specificity.rb', line 12

def <=>(other)
  [:a, :b, :c, :d].each do |name|
    result = send(name) <=> other.send(name)
    return result unless result == 0
  end
  0
end

#inspectObject



28
29
30
# File 'lib/simple_selector/specificity.rb', line 28

def inspect
  "#<#{self.class} #{to_s.inspect}>"
end

#to_sObject



24
25
26
# File 'lib/simple_selector/specificity.rb', line 24

def to_s
  "#{a},#{b},#{c},#{d}"
end