Class: Dommy::FileList

Inherits:
Object
  • Object
show all
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.

Spec: https://w3c.github.io/FileAPI/#filelist-section

Instance Method Summary collapse

Methods included from Bridge::Methods

included

Constructor Details

#initialize(files = []) ⇒ FileList

Returns a new instance of FileList.



196
197
198
# File 'lib/dommy/blob.rb', line 196

def initialize(files = [])
  @files = files.to_a.freeze
end

Instance Method Details

#[](index) ⇒ Object



210
211
212
# File 'lib/dommy/blob.rb', line 210

def [](index)
  item(index)
end

#__js_call__(method, args) ⇒ Object



238
239
240
241
242
243
# File 'lib/dommy/blob.rb', line 238

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

#__js_get__(key) ⇒ Object



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

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



214
215
216
217
# File 'lib/dommy/blob.rb', line 214

def each(&block)
  @files.each(&block)
  self
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @files.empty?
end

#item(index) ⇒ Object



206
207
208
# File 'lib/dommy/blob.rb', line 206

def item(index)
  @files[index.to_i]
end

#lengthObject Also known as: size



200
201
202
# File 'lib/dommy/blob.rb', line 200

def length
  @files.length
end

#to_aObject



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

def to_a
  @files.dup
end