Class: Dommy::File

Inherits:
Blob
  • Object
show all
Defined in:
lib/dommy/blob.rb

Overview

‘File` — Blob with a filename and an optional last-modified timestamp. Returned from `<input type=“file”>` / drag-and-drop, and accepted by FormData.

Spec: w3c.github.io/FileAPI/#file-section

Instance Attribute Summary collapse

Attributes inherited from Blob

#size, #type

Instance Method Summary collapse

Methods inherited from Blob

#__dommy_bytes__, #__js_call__, #array_buffer, #slice, #text

Methods included from Bridge::Methods

included

Constructor Details

#initialize(parts, name, options = {}, window = nil) ⇒ File

Returns a new instance of File.



126
127
128
129
130
131
# File 'lib/dommy/blob.rb', line 126

def initialize(parts, name, options = {}, window = nil)
  super(parts, options, window)
  @name = name.to_s
  raw_lm = options["lastModified"] || options[:lastModified]
  @last_modified = (raw_lm || (Time.now.to_f * 1000)).to_i
end

Instance Attribute Details

#last_modifiedObject (readonly)

Returns the value of attribute last_modified.



124
125
126
# File 'lib/dommy/blob.rb', line 124

def last_modified
  @last_modified
end

#nameObject (readonly)

Returns the value of attribute name.



124
125
126
# File 'lib/dommy/blob.rb', line 124

def name
  @name
end

Instance Method Details

#__js_get__(key) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# File 'lib/dommy/blob.rb', line 133

def __js_get__(key)
  case key
  when "name"
    @name
  when "lastModified"
    @last_modified
  else
    super
  end
end