Sha256: 13e6ba7db6d213a73b3923209a0776457bf5ac06585fc6da2de78cd3733910ce

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# backtick_javascript: true

module Browser
  class FileList
    include Enumerable

    # @param native [JS] the native FileList object to wrap
    def initialize native
      @native = `#{native} || []`
      @files = length.times.each_with_object([]) { |index, array|
        array[index] = ::Browser::File.new(`#@native[index]`)
      }
    end

    # @param index [Integer] the index of the file in the list
    # @return [Browser::FileList::File] the file at the specified index
    def [] index
      @files[index]
    end

    # @return [Integer] the number of files in this list
    def length
      `#@native.length`
    end
    alias size length

    # Call the given block for each file in the list
    #
    # @yieldparam file [Browser::FileList::File]
    def each &block
      @files.each do |file|
        block.call file
      end
    end

    # Convert this FileList into an array
    def to_a
      @files.dup # Don't return a value that can mutate our internal state
    end
    alias to_ary to_a

    # @return [String] a string representation of this FileList
    def to_s
      @files.to_s
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
isomorfeus-preact-23.9.0.rc2 lib/browser_auto/browser/file_list.rb
isomorfeus-preact-23.9.0.rc1 lib/browser_auto/browser/file_list.rb