Class: NZBGet::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/nzbget/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/nzbget/group.rb', line 3

def attributes
  @attributes
end

#positionObject

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

#deleteObject



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

Returns:

  • (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

#inspectObject



36
37
38
# File 'lib/nzbget/group.rb', line 36

def inspect
  "#<#{self.class} name=\"#{self.name}\">"
end

#move(offset_or_sym) ⇒ Object

Raises:

  • (ArgumentError)


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

#nameObject



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

#percentageObject



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

#resumeObject



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