Class: Vetinari::Dcc::Incoming::File
- Inherits:
-
Object
- Object
- Vetinari::Dcc::Incoming::File
- Includes:
- Celluloid::IO, Celluloid::Notifications
- Defined in:
- lib/vetinari/dcc/incoming/file.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#filesize ⇒ Object
readonly
Returns the value of attribute filesize.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#state ⇒ Object
Returns the value of attribute state.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #accept(directory = '~/Downloads/', resume = false) ⇒ Object
-
#initialize(user, filename, ip, port, filesize, bot) ⇒ File
constructor
A new instance of File.
- #inspect ⇒ Object
- #resume_accepted(position) ⇒ Object
Constructor Details
#initialize(user, filename, ip, port, filesize, bot) ⇒ File
Returns a new instance of File.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 9 def initialize(user, filename, ip, port, filesize, bot) @user = user @filename = filename @ip = ip @port = port @filesize = filesize @bot = bot @mutex = Mutex.new self.state = :pending end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 7 def filename @filename end |
#filesize ⇒ Object (readonly)
Returns the value of attribute filesize.
7 8 9 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 7 def filesize @filesize end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
7 8 9 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 7 def ip @ip end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 7 def port @port end |
#state ⇒ Object
Returns the value of attribute state.
7 8 9 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 7 def state @state end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 7 def user @user end |
Instance Method Details
#accept(directory = '~/Downloads/', resume = false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 21 def accept(directory = '~/Downloads/', resume = false) if @state == :pending self.state = :accepted directory = ::File.(directory) @filepath = ::File.join(directory, @filename) if resume && resumable? resume_transfer else download end end end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 35 def inspect "#<File filename=#{@filename} filesize=#{@filesize} user=#{@user.inspect}" end |
#resume_accepted(position) ⇒ Object
39 40 41 42 |
# File 'lib/vetinari/dcc/incoming/file.rb', line 39 def resume_accepted(position) self.state = :resume_accepted download(position) end |