Class: Dommy::CSSRuleList
- Inherits:
-
Object
- Object
- Dommy::CSSRuleList
- 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
- #[](index) ⇒ Object
- #__clear__ ⇒ Object
- #__delete_at__(index) ⇒ Object
- #__insert__(index, rule) ⇒ Object
- #__js_call__(method, args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #each(&blk) ⇒ Object
-
#initialize ⇒ CSSRuleList
constructor
A new instance of CSSRuleList.
- #item(index) ⇒ Object
- #length ⇒ Object (also: #size)
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ CSSRuleList
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 |
#length ⇒ Object Also known as: size
151 152 153 |
# File 'lib/dommy/css.rb', line 151 def length @rules.length end |
#to_a ⇒ Object
172 173 174 |
# File 'lib/dommy/css.rb', line 172 def to_a @rules.dup end |