Class: Dommy::FileList

Inherits:
Object
  • Object
show all
Includes:
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: w3c.github.io/FileAPI/#filelist-section

Instance Method Summary collapse

Constructor Details

#initialize(files = []) ⇒ FileList

Returns a new instance of FileList.



135
136
137
# File 'lib/dommy/blob.rb', line 135

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

Instance Method Details

#[](index) ⇒ Object



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

def [](index)
  item(index)
end

#__js_call__(method, args) ⇒ Object



175
176
177
178
179
180
# File 'lib/dommy/blob.rb', line 175

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

#__js_get__(key) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/dommy/blob.rb', line 166

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



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

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

#empty?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/dommy/blob.rb', line 158

def empty?
  @files.empty?
end

#item(index) ⇒ Object



145
146
147
# File 'lib/dommy/blob.rb', line 145

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

#lengthObject Also known as: size



139
140
141
# File 'lib/dommy/blob.rb', line 139

def length
  @files.length
end

#to_aObject



162
163
164
# File 'lib/dommy/blob.rb', line 162

def to_a
  @files.dup
end