Class: Cataract::Declaration

Inherits:
Struct
  • Object
show all
Defined in:
lib/cataract/declaration.rb,
lib/cataract/declaration.rb

Overview

Represents a CSS property declaration.

Declaration is a Struct with fields: (property, value, important)

Examples:

Create a declaration

decl = Cataract::Declaration.new('color', 'red', false)
decl.property #=> "color"
decl.value #=> "red"
decl.important #=> false

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#importantBoolean

Whether the declaration has !important

Returns:

  • (Boolean)

    the current value of important



17
18
19
# File 'lib/cataract/declaration.rb', line 17

def important
  @important
end

#propertyString

CSS property name (lowercased)

Returns:

  • (String)

    the current value of property



17
18
19
# File 'lib/cataract/declaration.rb', line 17

def property
  @property
end

#valueString

CSS property value

Returns:

  • (String)

    the current value of value



17
18
19
# File 'lib/cataract/declaration.rb', line 17

def value
  @value
end

Instance Method Details

#custom_property?Boolean

Check if this declaration is a custom property (CSS variable).

Custom properties are properties that start with the "--" prefix.

Examples:

Custom property

decl = Cataract::Declaration.new('--color', 'red', false)
decl.custom_property? #=> true

Regular property

decl = Cataract::Declaration.new('color', 'red', false)
decl.custom_property? #=> false

Returns:

  • (Boolean)

    true if property is a custom property



33
34
35
# File 'lib/cataract/declaration.rb', line 33

def custom_property?
  property.start_with?('--')
end