Class: Dommy::FileList
- Inherits:
-
Object
- Object
- Dommy::FileList
- Includes:
- Bridge::Methods, Enumerable
- Defined in:
- lib/dommy/blob.rb
Overview
‘FileList` — immutable, ordered collection of File objects. Returned by `<input type=“file”>#files` and DataTransfer#files.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #__js_call__(method, args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(files = []) ⇒ FileList
constructor
A new instance of FileList.
- #item(index) ⇒ Object
- #length ⇒ Object (also: #size)
- #to_a ⇒ Object
Methods included from Bridge::Methods
Constructor Details
#initialize(files = []) ⇒ FileList
Returns a new instance of FileList.
152 153 154 |
# File 'lib/dommy/blob.rb', line 152 def initialize(files = []) @files = files.to_a.freeze end |
Instance Method Details
#[](index) ⇒ Object
166 167 168 |
# File 'lib/dommy/blob.rb', line 166 def [](index) item(index) end |
#__js_call__(method, args) ⇒ Object
194 195 196 197 198 199 |
# File 'lib/dommy/blob.rb', line 194 def __js_call__(method, args) case method when "item" item(args[0]) end end |
#__js_get__(key) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/dommy/blob.rb', line 183 def __js_get__(key) case key when "length" length else item(key.to_i) if key.is_a?(Integer) || key.to_s.match?(/\A-?\d+\z/) end end |
#each(&block) ⇒ Object
170 171 172 173 |
# File 'lib/dommy/blob.rb', line 170 def each(&block) @files.each(&block) self end |
#empty? ⇒ Boolean
175 176 177 |
# File 'lib/dommy/blob.rb', line 175 def empty? @files.empty? end |
#item(index) ⇒ Object
162 163 164 |
# File 'lib/dommy/blob.rb', line 162 def item(index) @files[index.to_i] end |
#length ⇒ Object Also known as: size
156 157 158 |
# File 'lib/dommy/blob.rb', line 156 def length @files.length end |
#to_a ⇒ Object
179 180 181 |
# File 'lib/dommy/blob.rb', line 179 def to_a @files.dup end |