Class: Dommy::CSSRuleList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dommy/css.rb

Overview

‘CSSRuleList` — indexed list of CSSRule, returned by `sheet.cssRules`. Live: mutations to the owning sheet are visible.

Instance Method Summary collapse

Constructor Details

#initializeCSSRuleList

Returns a new instance of CSSRuleList.



147
148
149
# File 'lib/dommy/css.rb', line 147

def initialize
  @rules = []
end

Instance Method Details

#[](index) ⇒ Object



164
165
166
# File 'lib/dommy/css.rb', line 164

def [](index)
  item(index)
end

#__clear__Object



184
185
186
# File 'lib/dommy/css.rb', line 184

def __clear__
  @rules.clear
end

#__delete_at__(index) ⇒ Object



180
181
182
# File 'lib/dommy/css.rb', line 180

def __delete_at__(index)
  @rules.delete_at(index)
end

#__insert__(index, rule) ⇒ Object



176
177
178
# File 'lib/dommy/css.rb', line 176

def __insert__(index, rule)
  @rules.insert(index, rule)
end

#__js_call__(method, args) ⇒ Object



199
200
201
202
203
204
# File 'lib/dommy/css.rb', line 199

def __js_call__(method, args)
  case method
  when "item"
    item(args[0])
  end
end

#__js_get__(key) ⇒ Object



188
189
190
191
192
193
194
195
196
197
# File 'lib/dommy/css.rb', line 188

def __js_get__(key)
  case key
  when "length"
    length
  else
    if key.is_a?(Integer) || key.to_s.match?(/\A\d+\z/)
      item(key.to_i)
    end
  end
end

#each(&blk) ⇒ Object



168
169
170
# File 'lib/dommy/css.rb', line 168

def each(&blk)
  @rules.each(&blk)
end

#item(index) ⇒ Object



157
158
159
160
161
162
# File 'lib/dommy/css.rb', line 157

def item(index)
  i = index.to_i
  return nil if i < 0 || i >= @rules.length

  @rules[i]
end

#lengthObject Also known as: size



151
152
153
# File 'lib/dommy/css.rb', line 151

def length
  @rules.length
end

#to_aObject



172
173
174
# File 'lib/dommy/css.rb', line 172

def to_a
  @rules.dup
end