Class: Shoes::Download

Inherits:
Object
  • Object
show all
Defined in:
shoes-core/lib/shoes/download.rb

Constant Summary collapse

UPDATE_STEPS =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, _parent, url, opts = {}, &blk) ⇒ Download

Returns a new instance of Download.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'shoes-core/lib/shoes/download.rb', line 19

def initialize(app, _parent, url, opts = {}, &blk)
  @app = app
  @url = url

  @opts = opts
  @body    = opts[:body]
  @headers = opts[:headers] || {}
  @method  = opts[:method] || "GET"

  initialize_blocks(app, blk)

  @gui = Shoes.backend_for(self)

  @response = HttpResponse.new
  @finished = false
  @transferred = 0
  @content_length = 1 # non zero initialized to avoid Zero Div Errors
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



15
16
17
# File 'shoes-core/lib/shoes/download.rb', line 15

def app
  @app
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



15
16
17
# File 'shoes-core/lib/shoes/download.rb', line 15

def content_length
  @content_length
end

#guiObject (readonly)

Returns the value of attribute gui.



15
16
17
# File 'shoes-core/lib/shoes/download.rb', line 15

def gui
  @gui
end

#progressObject (readonly)

Returns the value of attribute progress.



15
16
17
# File 'shoes-core/lib/shoes/download.rb', line 15

def progress
  @progress
end

#responseObject (readonly)

Returns the value of attribute response.



15
16
17
# File 'shoes-core/lib/shoes/download.rb', line 15

def response
  @response
end

#transferredObject (readonly)

Returns the value of attribute transferred.



15
16
17
# File 'shoes-core/lib/shoes/download.rb', line 15

def transferred
  @transferred
end

Instance Method Details

#abortObject



68
69
70
# File 'shoes-core/lib/shoes/download.rb', line 68

def abort
  @thread&.exit
end

#finished?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'shoes-core/lib/shoes/download.rb', line 54

def finished?
  @finished
end

#initialize_blocks(app, blk) ⇒ Object



38
39
40
41
42
43
44
# File 'shoes-core/lib/shoes/download.rb', line 38

def initialize_blocks(app, blk)
  slot = app.current_slot
  @blk = slot.create_bound_block(blk)
  @progress_blk = slot.create_bound_block(@opts[:progress])
  @finish_blk = slot.create_bound_block(@opts[:finish])
  @error_blk = slot.create_bound_block(@opts[:error] || default_error_proc)
end

#join_threadObject

needed for the specs (jay multi threading and specs)



59
60
61
# File 'shoes-core/lib/shoes/download.rb', line 59

def join_thread
  @thread&.join
end

#lengthObject

shoes 3 compatibility



73
74
75
# File 'shoes-core/lib/shoes/download.rb', line 73

def length
  @content_length
end

#percentObject



63
64
65
66
# File 'shoes-core/lib/shoes/download.rb', line 63

def percent
  return 0 if @transferred.nil? || @content_length.nil?
  @transferred * 100 / @content_length
end

#startObject



46
47
48
# File 'shoes-core/lib/shoes/download.rb', line 46

def start
  start_download
end

#started?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'shoes-core/lib/shoes/download.rb', line 50

def started?
  @started
end