Class: Habaki::MediaQueryExpression

Inherits:
Node
  • Object
show all
Defined in:
lib/habaki/media_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#to_s

Constructor Details

#initializeMediaQueryExpression

Returns a new instance of MediaQueryExpression.



8
9
10
# File 'lib/habaki/media_rule.rb', line 8

def initialize
  @values = Values.new
end

Instance Attribute Details

#featureString

Returns:



4
5
6
# File 'lib/habaki/media_rule.rb', line 4

def feature
  @feature
end

#valuesValues

Returns:



6
7
8
# File 'lib/habaki/media_rule.rb', line 6

def values
  @values
end

Instance Method Details

#media_match?(media) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/habaki/media_rule.rb', line 19

def media_match?(media)
  case @feature
  when "min-width"
    return true unless media.width
    media.width >= value.to_px
  when "max-width"
    return true unless media.width
    media.width <= value.to_px
  when "min-height"
    return true unless media.height
    media.height >= value.to_px
  when "max-height"
    return true unless media.height
    media.height <= value.to_px
  end
end

#read_from_katana(exp) ⇒ 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.

Parameters:



45
46
47
48
49
50
# File 'lib/habaki/media_rule.rb', line 45

def read_from_katana(exp)
  @feature = exp.feature
  if exp.values
    @values = Values.read_from_katana(exp.values)
  end
end

#string(format = Formatter::Base.new) ⇒ String

Parameters:

Returns:



38
39
40
# File 'lib/habaki/media_rule.rb', line 38

def string(format = Formatter::Base.new)
  "(#{@feature}#{@values.any? ? ": #{@values.string(format)}" : ""})"
end

#valueValue

Returns:



13
14
15
# File 'lib/habaki/media_rule.rb', line 13

def value
  @values.first
end