Class: Cataract::MediaQuery
- Inherits:
-
Struct
- Object
- Struct
- Cataract::MediaQuery
- Defined in:
- lib/cataract/media_query.rb
Overview
MediaQuery represents a CSS media query constraint.
Media queries are stored in the Stylesheet and referenced by Rules via media_query_id. This allows efficient tracking of which rules apply to which media contexts.
Instance Attribute Summary collapse
-
#conditions ⇒ String?
Additional conditions like "(min-width: 768px)", or nil if none.
-
#id ⇒ Integer
Unique identifier for this media query within the stylesheet.
-
#type ⇒ Symbol
Primary media type (:screen, :print, :all, etc.).
Class Method Summary collapse
-
.make(id:, type:, conditions: nil) ⇒ MediaQuery
Create a MediaQuery with keyword arguments for readability.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare media queries for equality based on type and conditions.
-
#hash ⇒ Integer
Generate hash code for this media query.
-
#inspect ⇒ String
Get detailed inspection string.
-
#text ⇒ String
Get the full media query text.
-
#to_s ⇒ String
Get a human-readable representation.
Instance Attribute Details
#conditions ⇒ String?
Additional conditions like "(min-width: 768px)", or nil if none
19 20 21 |
# File 'lib/cataract/media_query.rb', line 19 def conditions @conditions end |
#id ⇒ Integer
Unique identifier for this media query within the stylesheet
19 20 21 |
# File 'lib/cataract/media_query.rb', line 19 def id @id end |
#type ⇒ Symbol
Primary media type (:screen, :print, :all, etc.)
19 20 21 |
# File 'lib/cataract/media_query.rb', line 19 def type @type end |
Class Method Details
.make(id:, type:, conditions: nil) ⇒ MediaQuery
Create a MediaQuery with keyword arguments for readability.
32 33 34 |
# File 'lib/cataract/media_query.rb', line 32 def self.make(id:, type:, conditions: nil) new(id, type, conditions) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare media queries for equality based on type and conditions.
Two media queries are equal if they have the same type and conditions. IDs are not considered since they're internal identifiers.
65 66 67 68 69 70 71 72 |
# File 'lib/cataract/media_query.rb', line 65 def ==(other) case other when MediaQuery type == other.type && conditions == other.conditions else false end end |
#hash ⇒ Integer
Generate hash code for this media query.
Hash is based on type and conditions to match equality semantics.
80 81 82 |
# File 'lib/cataract/media_query.rb', line 80 def hash [self.class, type, conditions].hash end |
#inspect ⇒ String
Get detailed inspection string.
94 95 96 |
# File 'lib/cataract/media_query.rb', line 94 def inspect "#<MediaQuery id=#{id} type=#{type.inspect} conditions=#{conditions.inspect}>" end |
#text ⇒ String
Get the full media query text.
Reconstructs the media query string from type and conditions.
49 50 51 52 53 54 55 56 |
# File 'lib/cataract/media_query.rb', line 49 def text if conditions # If type is :all, just return conditions (don't say "all and ...") type == :all ? conditions : "#{type} and #{conditions}" else type.to_s end end |
#to_s ⇒ String
Get a human-readable representation.
87 88 89 |
# File 'lib/cataract/media_query.rb', line 87 def to_s text end |