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
permalink #kind ⇒ Symbol (readonly)
Returns kind of an item: :string or :file.
64 65 66 |
# File 'opal/browser/event/data_transfer.rb', line 64 def kind `#@native.kind` end |
Instance Method Details
permalink #file? ⇒ Boolean
Some files can't be resolved...
69 |
# File 'opal/browser/event/data_transfer.rb', line 69 def file?; kind == 'file' && to_file; end |
permalink #string? ⇒ Boolean
68 |
# File 'opal/browser/event/data_transfer.rb', line 68 def string?; kind == 'string'; end |
permalink #to_file ⇒ Object
Convert to file or return nil if impossible
90 91 92 93 |
# File 'opal/browser/event/data_transfer.rb', line 90 def to_file as_file = `#@native.getAsFile()` File.new(as_file) if as_file end |
permalink #to_string(&block) ⇒ Object
Convert to string and call back once ready, or return a promise if a block isn't given.
79 80 81 82 83 84 85 86 87 |
# File 'opal/browser/event/data_transfer.rb', line 79 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 |