Class: Browser::FileList

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/browser/file_list.rb

Defined Under Namespace

Classes: File

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ FileList

Returns a new instance of FileList.

Parameters:

  • native (JS)

    the native FileList object to wrap



6
7
8
9
10
11
# File 'lib/browser/file_list.rb', line 6

def initialize native
  @native = `#{native} || []`
  @files = length.times.each_with_object([]) { |index, array|
    array[index] = File.new(`#@native[index]`)
  }
end

Instance Method Details

#[](index) ⇒ Browser::FileList::File

Returns the file at the specified index.

Parameters:

  • index (Integer)

    the index of the file in the list

Returns:



15
16
17
# File 'lib/browser/file_list.rb', line 15

def [] index
  @files[index]
end

#each {|file| ... } ⇒ Object

Call the given block for each file in the list

Yield Parameters:



28
29
30
31
32
# File 'lib/browser/file_list.rb', line 28

def each &block
  @files.each do |file|
    block.call file
  end
end

#lengthInteger Also known as: size

Returns the number of files in this list.

Returns:

  • (Integer)

    the number of files in this list



20
21
22
# File 'lib/browser/file_list.rb', line 20

def length
  `#@native.length`
end

#to_aObject Also known as: to_ary

Convert this FileList into an array



35
36
37
# File 'lib/browser/file_list.rb', line 35

def to_a
  @files.dup # Don't return a value that can mutate our internal state
end

#to_sString

Returns a string representation of this FileList.

Returns:

  • (String)

    a string representation of this FileList



41
42
43
# File 'lib/browser/file_list.rb', line 41

def to_s
  @files.to_s
end