Class: Apropos::MediaQuery
- Inherits:
-
Object
- Object
- Apropos::MediaQuery
- Defined in:
- lib/apropos/media_query.rb
Overview
MediaQuery wraps a media query string with several features:
-
Parenthesizes queries when necessary
-
Can be combined with other MediaQuery objects
-
Can be compared to ClassList or MediaQuery objects via #type, #sort_value
-
Can be converted to CSS output
Instance Attribute Summary collapse
-
#query_list ⇒ Object
readonly
Returns the value of attribute query_list.
-
#sort_value ⇒ Object
readonly
Returns the value of attribute sort_value.
Instance Method Summary collapse
- #combine(other) ⇒ Object
-
#initialize(query_string, sort_value = 0) ⇒ MediaQuery
constructor
A new instance of MediaQuery.
- #parenthesize(query) ⇒ Object
- #to_css ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(query_string, sort_value = 0) ⇒ MediaQuery
Returns a new instance of MediaQuery.
10 11 12 13 |
# File 'lib/apropos/media_query.rb', line 10 def initialize(query_string, sort_value=0) @query_list = query_string.split(',').map { |q| parenthesize(q.strip) } @sort_value = sort_value end |
Instance Attribute Details
#query_list ⇒ Object (readonly)
Returns the value of attribute query_list.
8 9 10 |
# File 'lib/apropos/media_query.rb', line 8 def query_list @query_list end |
#sort_value ⇒ Object (readonly)
Returns the value of attribute sort_value.
8 9 10 |
# File 'lib/apropos/media_query.rb', line 8 def sort_value @sort_value end |
Instance Method Details
#combine(other) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/apropos/media_query.rb', line 23 def combine(other) other_ql = other.query_list combo = query_list.map do |q| other_ql.map do |q2| "#{q} and #{q2}" end end.flatten self.class.new(combo.join(', ')) end |
#parenthesize(query) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/apropos/media_query.rb', line 15 def parenthesize(query) unless query =~ /^\(.+\)$/ "(#{query})" else query end end |
#to_css ⇒ Object
33 34 35 |
# File 'lib/apropos/media_query.rb', line 33 def to_css query_list.join(", ") end |
#type ⇒ Object
37 38 39 |
# File 'lib/apropos/media_query.rb', line 37 def type "media" end |