Class: Browser::Event::DataTransfer::Item

Inherits:
Object
  • Object
show all
Includes:
NativeCachedWrapper
Defined in:
opal/browser/event/data_transfer.rb

Overview

An instance of DataTransferItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NativeCachedWrapper

#restricted?, #set_native_reference

Instance Attribute Details

#kindSymbol (readonly)

Returns kind of an item: :string or :file.

Returns:

  • (Symbol)

    kind of an item: :string or :file


62
63
64
# File 'opal/browser/event/data_transfer.rb', line 62

def kind
  `#@native.kind`
end

#typeString (readonly)

Returns mime type of an item.

Returns:

  • (String)

    mime type of an item


71
72
73
# File 'opal/browser/event/data_transfer.rb', line 71

def type
  `#@native.type`
end

Instance Method Details

#file?Boolean

Some files can't be resolved...

Returns:

  • (Boolean)

67
# File 'opal/browser/event/data_transfer.rb', line 67

def file?;   kind == 'file' && to_file;  end

#string?Boolean

Returns:

  • (Boolean)

66
# File 'opal/browser/event/data_transfer.rb', line 66

def string?; kind == 'string';           end

#to_fileObject

Convert to file or return nil if impossible


88
89
90
91
# File 'opal/browser/event/data_transfer.rb', line 88

def to_file
  as_file = `#@native.getAsFile()`
  File.new(as_file) if as_file
end

#to_string(&block) ⇒ Object

Convert to string and call back once ready, or return a promise if a block isn't given.


77
78
79
80
81
82
83
84
85
# File 'opal/browser/event/data_transfer.rb', line 77

def to_string(&block)
  promise = nil
  if !block
    promise = Promise.new
    block = proc { |i| promise.resolve(i) }
  end
  `#@native.getAsString(#{block.to_n})`
  return promise
end