Class: NZBGet::Group
- Inherits:
-
Object
- Object
- NZBGet::Group
- Defined in:
- lib/nzbget/group.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #category=(category = '') ⇒ Object
- #delete ⇒ Object
- #downloaded(format = :bytes) ⇒ Object
- #first? ⇒ Boolean
- #formatted_response(bytes, format) ⇒ Object
-
#initialize(nzbget, position, hash) ⇒ Group
constructor
A new instance of Group.
- #inspect ⇒ Object
- #move(offset_or_sym) ⇒ Object
- #name ⇒ Object
- #pause(pars = nil) ⇒ Object
- #paused(format = :bytes) ⇒ Object
- #percentage ⇒ Object
- #remaining(format = :bytes) ⇒ Object
- #resume ⇒ Object
- #size(format = :bytes) ⇒ Object
Constructor Details
#initialize(nzbget, position, hash) ⇒ Group
Returns a new instance of Group.
5 6 7 8 9 |
# File 'lib/nzbget/group.rb', line 5 def initialize(nzbget, position, hash) @nzbget = nzbget @position = position @attributes = hash end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/nzbget/group.rb', line 3 def attributes @attributes end |
#position ⇒ Object
Returns the value of attribute position.
3 4 5 |
# File 'lib/nzbget/group.rb', line 3 def position @position end |
Instance Method Details
#category=(category = '') ⇒ Object
11 12 13 |
# File 'lib/nzbget/group.rb', line 11 def category=(category = '') @nzbget.editqueue('GroupSetCategory', 0, category, @attributes['LastID']) end |
#delete ⇒ Object
15 16 17 |
# File 'lib/nzbget/group.rb', line 15 def delete @nzbget.editqueue('GroupDelete', 0, '', @attributes['LastID']) end |
#downloaded(format = :bytes) ⇒ Object
19 20 21 |
# File 'lib/nzbget/group.rb', line 19 def downloaded(format = :bytes) formatted_response([size - remaining, 0].max, format) end |
#first? ⇒ Boolean
23 24 25 |
# File 'lib/nzbget/group.rb', line 23 def first? @position == 0 end |
#formatted_response(bytes, format) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/nzbget/group.rb', line 27 def formatted_response(bytes, format) case format when :bytes, :b then bytes when :kilobytes, :kb then bytes.to_f / 1024 when :megabytes, :mb then bytes.to_f / 1024 ** 2 when :gigabytes, :gb then bytes.to_f / 1024 ** 3 end end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/nzbget/group.rb', line 36 def inspect "#<#{self.class} name=\"#{self.name}\">" end |
#move(offset_or_sym) ⇒ Object
44 45 46 47 48 |
# File 'lib/nzbget/group.rb', line 44 def move(offset_or_sym) return move_to_offset(offset_or_sym) if offset_or_sym.is_a? Fixnum return move_to_symbol(offset_or_sym) if offset_or_sym.is_a? Symbol raise ArgumentError end |
#name ⇒ Object
40 41 42 |
# File 'lib/nzbget/group.rb', line 40 def name @attributes['NZBNicename'] end |
#pause(pars = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nzbget/group.rb', line 54 def pause(pars = nil) command = unless pars 'GroupPause' else if pars == :all 'GroupPauseAllPars' elsif pars == :extra 'GroupPauseExtraPars' else raise ArgumentError end end @nzbget.editqueue(command, 0, '', @attributes['LastID']) end |
#paused(format = :bytes) ⇒ Object
71 72 73 |
# File 'lib/nzbget/group.rb', line 71 def paused(format = :bytes) formatted_response(@attributes['PausedSizeMB'] * 1024, format) end |
#percentage ⇒ Object
50 51 52 |
# File 'lib/nzbget/group.rb', line 50 def percentage (downloaded + paused) * 100.0 / size end |
#remaining(format = :bytes) ⇒ Object
75 76 77 |
# File 'lib/nzbget/group.rb', line 75 def remaining(format = :bytes) formatted_response(@attributes['RemainingSizeMB'] * 1024, format) end |
#resume ⇒ Object
79 80 81 |
# File 'lib/nzbget/group.rb', line 79 def resume @nzbget.editqueue('GroupResume', 0, '', @attributes['LastID']) end |
#size(format = :bytes) ⇒ Object
83 84 85 |
# File 'lib/nzbget/group.rb', line 83 def size(format = :bytes) formatted_response(@attributes['FileSizeMB'] * 1024, format) end |