Class: CssCompare::CSS::Component::FontFace

Inherits:
Base
  • Object
show all
Defined in:
lib/css_compare/css/component/font_face.rb

Overview

Represents the @font-face directive.

Multiple @font-face rules can be used to construct font families with a variety of faces. Each @font-face rule specifies a value for every font descriptor, either implicitly or explicitly. Those not given explicit values in the rule take the initial value listed with each descriptor in the w3.org specification.

If multiple declarations of @font-face rules, that share the same ‘font-family` and `src` values are present, the last declaration overrides the other.

‘Font-family` property is saved downcased, since the user agents, when matching font-family names, do it in a case-insensitive manner.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#equals?

Constructor Details

#initialize(children) ⇒ FontFace

Returns a new instance of FontFace.

Parameters:

  • children (Array<Sass::Tree::PropNode>)

    font properties



26
27
28
29
30
# File 'lib/css_compare/css/component/font_face.rb', line 26

def initialize(children)
  @declarations = {}
  init_declarations
  process_declarations(children)
end

Instance Attribute Details

#declarationsObject (readonly)

Returns the value of attribute declarations.



23
24
25
# File 'lib/css_compare/css/component/font_face.rb', line 23

def declarations
  @declarations
end

Instance Method Details

#==(other) ⇒ Object

Checks, whether two @font-face declarations are equal.

No need to check, whether both font-faces have the same keys, since they are also initialized with the default values.

Parameters:

  • other (FontFace)

    the @font-face to compare this with.



40
41
42
# File 'lib/css_compare/css/component/font_face.rb', line 40

def ==(other)
  @declarations.all? { |k, _| @declarations[k] == other.declarations[k] }
end

#familyString?

Returns font-family name, if set.

Returns:

  • (String, nil)

    font-family name, if set



56
57
58
# File 'lib/css_compare/css/component/font_face.rb', line 56

def family
  @declarations['font-family']
end

#srcString?

Returns the source of the font if set.

Returns:

  • (String, nil)

    the source of the font if set



61
62
63
# File 'lib/css_compare/css/component/font_face.rb', line 61

def src
  @declarations['src']
end

#to_jsonHash

Creates the JSON representation of this object.

Returns:

  • (Hash)


68
69
70
# File 'lib/css_compare/css/component/font_face.rb', line 68

def to_json
  @declarations
end

#valid?Boolean

Tells, whether this rule is valid or not.

@font-face rules require a font-family and src descriptor; if either of these are missing, the @font-face rule is invalid and must be ignored entirely.

Returns:

  • (Boolean)


51
52
53
# File 'lib/css_compare/css/component/font_face.rb', line 51

def valid?
  family && src
end