Class: Habaki::MediaQuery
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ MediaQuery
constructor
A new instance of MediaQuery.
- #media_match?(media) ⇒ Boolean
- #media_match_type?(mediatype = "all") ⇒ Boolean
- #read_from_katana(med) ⇒ void private
- #string(format = Formatter::Base.new) ⇒ String
Methods inherited from Node
Constructor Details
#initialize ⇒ MediaQuery
Returns a new instance of MediaQuery.
61 62 63 |
# File 'lib/habaki/media_rule.rb', line 61 def initialize @expressions = [] end |
Instance Attribute Details
#expressions ⇒ Array<MediaQueryExpression>
59 60 61 |
# File 'lib/habaki/media_rule.rb', line 59 def expressions @expressions end |
#restrictor ⇒ Symbol
57 58 59 |
# File 'lib/habaki/media_rule.rb', line 57 def restrictor @restrictor end |
Instance Method Details
#media_match?(media) ⇒ Boolean
78 79 80 81 82 83 84 |
# File 'lib/habaki/media_rule.rb', line 78 def media_match?(media) return false unless media_match_type?(media.type) @expressions.each do |exp| return false unless exp.media_match?(media) end true end |
#media_match_type?(mediatype = "all") ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/habaki/media_rule.rb', line 65 def media_match_type?(mediatype = "all") return true unless mediatype case @restrictor when :none, :only @type == mediatype || @type == "all" || !mediatype when :not @type != mediatype else false end end |
#read_from_katana(med) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
102 103 104 105 106 107 108 |
# File 'lib/habaki/media_rule.rb', line 102 def read_from_katana(med) @type = med.type @restrictor = med.restrictor med.expressions.each do |exp| @expressions << MediaQueryExpression.read_from_katana(exp) end end |
#string(format = Formatter::Base.new) ⇒ String
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/habaki/media_rule.rb', line 88 def string(format = Formatter::Base.new) str = (@restrictor != :none ? @restrictor.to_s + " " : "") + (@type ? @type : "") if @expressions.any? @expressions.each do |exp| str += " and " if str != "" str += exp.string(format) end end str end |