Class: Csscss::Declaration

Inherits:
Struct
  • Object
show all
Defined in:
lib/csscss/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentsObject

Returns the value of attribute parents

Returns:

  • (Object)

    the current value of parents



2
3
4
# File 'lib/csscss/types.rb', line 2

def parents
  @parents
end

#propertyObject

Returns the value of attribute property

Returns:

  • (Object)

    the current value of property



2
3
4
# File 'lib/csscss/types.rb', line 2

def property
  @property
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



2
3
4
# File 'lib/csscss/types.rb', line 2

def value
  @value
end

Class Method Details

.from_csspool(dec) ⇒ Object



3
4
5
# File 'lib/csscss/types.rb', line 3

def self.from_csspool(dec)
  new(dec.property.to_s.downcase, dec.expressions.join(" ").downcase)
end

.from_parser(property, value, clean = true) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/csscss/types.rb', line 7

def self.from_parser(property, value, clean = true)
  value = value.to_s
  property = property.to_s
  if clean
    value = value.downcase
    property = property.downcase
  end
  new(property, value.strip)
end

Instance Method Details

#<(other) ⇒ Object



56
57
58
# File 'lib/csscss/types.rb', line 56

def <(other)
  other > self
end

#<=>(other) ⇒ Object



48
49
50
# File 'lib/csscss/types.rb', line 48

def <=>(other)
  property <=> other.property
end

#==(other) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/csscss/types.rb', line 31

def ==(other)
  if other.respond_to?(:property) && other.respond_to?(:value)
    # using eql? tanks performance
    property == other.property && normalize_value(value) == normalize_value(other.value)
  else
    false
  end
end

#>(other) ⇒ Object



52
53
54
# File 'lib/csscss/types.rb', line 52

def >(other)
  other.derivative? && other.parents.include?(self)
end

#derivative?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/csscss/types.rb', line 17

def derivative?
  !parents.nil?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/csscss/types.rb', line 44

def eql?(other)
  hash == other.hash
end

#hashObject



40
41
42
# File 'lib/csscss/types.rb', line 40

def hash
  [property, normalize_value(value)].hash
end

#inspectObject



64
65
66
67
68
69
70
# File 'lib/csscss/types.rb', line 64

def inspect
  if parents
    "<#{self.class} #{to_s} (parents: #{parents})>"
  else
    "<#{self.class} #{to_s}>"
  end
end

#to_sObject



60
61
62
# File 'lib/csscss/types.rb', line 60

def to_s
  "#{property}: #{value}"
end

#without_parentsObject



21
22
23
24
25
26
27
28
29
# File 'lib/csscss/types.rb', line 21

def without_parents
  if derivative?
    dup.tap do |duped|
      duped.parents = nil
    end
  else
    self
  end
end