Class: CssCompare::CSS::Component::FontFace
- 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
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Checks, whether two @font-face declarations are equal.
-
#family ⇒ String?
Font-family name, if set.
-
#initialize(children) ⇒ FontFace
constructor
A new instance of FontFace.
-
#src ⇒ String?
The source of the font if set.
-
#to_json ⇒ Hash
Creates the JSON representation of this object.
-
#valid? ⇒ Boolean
Tells, whether this rule is valid or not.
Methods inherited from Base
Constructor Details
#initialize(children) ⇒ FontFace
Returns a new instance of FontFace.
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
#declarations ⇒ Object (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.
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 |
#family ⇒ String?
Returns 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 |
#src ⇒ String?
Returns 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_json ⇒ Hash
Creates the JSON representation of this object.
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.
51 52 53 |
# File 'lib/css_compare/css/component/font_face.rb', line 51 def valid? family && src end |