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.



149
150
151
# File 'lib/dommy/css.rb', line 149

def initialize
  @rules = []
end

Instance Method Details

#[](index) ⇒ Object



166
167
168
# File 'lib/dommy/css.rb', line 166

def [](index)
  item(index)
end

#__internal_clear__Object



186
187
188
# File 'lib/dommy/css.rb', line 186

def __internal_clear__
  @rules.clear
end

#__internal_delete_at__(index) ⇒ Object



182
183
184
# File 'lib/dommy/css.rb', line 182

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

#__internal_insert__(index, rule) ⇒ Object



178
179
180
# File 'lib/dommy/css.rb', line 178

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

#__js_call__(method, args) ⇒ Object



203
204
205
206
207
208
# File 'lib/dommy/css.rb', line 203

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

#__js_get__(key) ⇒ Object



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

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



170
171
172
# File 'lib/dommy/css.rb', line 170

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

#item(index) ⇒ Object



159
160
161
162
163
164
# File 'lib/dommy/css.rb', line 159

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

  @rules[i]
end

#lengthObject Also known as: size



153
154
155
# File 'lib/dommy/css.rb', line 153

def length
  @rules.length
end

#to_aObject



174
175
176
# File 'lib/dommy/css.rb', line 174

def to_a
  @rules.dup
end