Class: Dommy::CSSRuleList

Inherits:
Object
  • Object
show all
Includes:
Bridge::Methods, 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

Methods included from Bridge::Methods

included

Constructor Details

#initializeCSSRuleList

Returns a new instance of CSSRuleList.



219
220
221
# File 'lib/dommy/css.rb', line 219

def initialize
  @rules = []
end

Instance Method Details

#[](index) ⇒ Object



236
237
238
# File 'lib/dommy/css.rb', line 236

def [](index)
  item(index)
end

#__internal_clear__Object



256
257
258
# File 'lib/dommy/css.rb', line 256

def __internal_clear__
  @rules.clear
end

#__internal_delete_at__(index) ⇒ Object



252
253
254
# File 'lib/dommy/css.rb', line 252

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

#__internal_insert__(index, rule) ⇒ Object



248
249
250
# File 'lib/dommy/css.rb', line 248

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

#__js_call__(method, args) ⇒ Object



273
274
275
276
277
278
# File 'lib/dommy/css.rb', line 273

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

#__js_get__(key) ⇒ Object



260
261
262
263
264
265
266
267
268
269
# File 'lib/dommy/css.rb', line 260

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



240
241
242
# File 'lib/dommy/css.rb', line 240

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

#item(index) ⇒ Object



229
230
231
232
233
234
# File 'lib/dommy/css.rb', line 229

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

  @rules[i]
end

#lengthObject Also known as: size



223
224
225
# File 'lib/dommy/css.rb', line 223

def length
  @rules.length
end

#to_aObject



244
245
246
# File 'lib/dommy/css.rb', line 244

def to_a
  @rules.dup
end