Class: Roadie::StyleProperty Private

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/roadie/style_property.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Domain object for a CSS property such as “color: red !important”.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property, value, important, specificity) ⇒ StyleProperty

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of StyleProperty.



28
29
30
31
32
33
# File 'lib/roadie/style_property.rb', line 28

def initialize(property, value, important, specificity)
  @property = property
  @value = value
  @important = important
  @specificity = specificity
end

Instance Attribute Details

#importantBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

if the property is “!important”.

Returns:

  • (Boolean)

    the current value of important



9
10
11
# File 'lib/roadie/style_property.rb', line 9

def important
  @important
end

#propertyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Rename #property to #name



9
10
11
# File 'lib/roadie/style_property.rb', line 9

def property
  @property
end

#specificityInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

specificity of parent Roadie::Selector. Used to compare/sort.

Returns:

  • (Integer)

    the current value of specificity



9
10
11
# File 'lib/roadie/style_property.rb', line 9

def specificity
  @specificity
end

#valueString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

value of the property (such as “5px solid green”).

Returns:

  • (String)

    the current value of value



9
10
11
# File 'lib/roadie/style_property.rb', line 9

def value
  @value
end

Class Method Details

.parse(declaration, specificity) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse a property string.

Examples:

property = Roadie::StyleProperty.parse("color: green")
property.property # => "color"
property.value # => "green"
property.important? # => false


24
25
26
# File 'lib/roadie/style_property.rb', line 24

def self.parse(declaration, specificity)
  allocate.send :read_declaration!, declaration, specificity
end

Instance Method Details

#<=>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compare another Roadie::StyleProperty. Important styles are “greater than” non-important ones; otherwise the specificity declares order.



41
42
43
44
45
46
47
# File 'lib/roadie/style_property.rb', line 41

def <=>(other)
  if important == other.important
    specificity <=> other.specificity
  else
    important ? 1 : -1
  end
end

#important?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
# File 'lib/roadie/style_property.rb', line 35

def important?
  @important
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/roadie/style_property.rb', line 53

def inspect
  "#{to_s} (#{specificity})"
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/roadie/style_property.rb', line 49

def to_s
  [property, value_with_important].join(':')
end