Class: Browser::Event::DataTransfer::Item
- Includes:
- NativeCachedWrapper
- Defined in:
- opal/browser/event/data_transfer.rb
Overview
An instance of DataTransferItem
Instance Attribute Summary collapse
-
#kind ⇒ Symbol
readonly
Kind of an item: :string or :file.
-
#type ⇒ String
readonly
Mime type of an item.
Instance Method Summary collapse
-
#file? ⇒ Boolean
Some files can't be resolved...
- #string? ⇒ Boolean
-
#to_file ⇒ Object
Convert to file or return nil if impossible.
-
#to_string(&block) ⇒ Object
Convert to string and call back once ready, or return a promise if a block isn't given.
Methods included from NativeCachedWrapper
#restricted?, #set_native_reference
Instance Attribute Details
#kind ⇒ Symbol (readonly)
62 63 64 |
# File 'opal/browser/event/data_transfer.rb', line 62 def kind `#@native.kind` end |
#type ⇒ String (readonly)
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...
67 |
# File 'opal/browser/event/data_transfer.rb', line 67 def file?; kind == 'file' && to_file; end |
#string? ⇒ Boolean
66 |
# File 'opal/browser/event/data_transfer.rb', line 66 def string?; kind == 'string'; end |
#to_file ⇒ Object
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 |