Class: Nzbmatrix::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/nzbmatrix/search_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_response, client) ⇒ SearchResult

Returns a new instance of SearchResult.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nzbmatrix/search_result.rb', line 22

def initialize(api_response, client)
  @client = client
  
  @id = api_response["NZBID"].to_i
  @name = api_response["NZBNAME"]
  @link = api_response["LINK"]
  @size = api_response["SIZE"].to_f
  @index_date = Time.parse(api_response["INDEX_DATE"]) rescue nil
  @usenet_date = Time.parse(api_response["USENET_DATE"]) rescue nil
  @category = api_response["CATEGORY"]
  @group = api_response["GROUP"]
  @comments = api_response["COMMENTS"].to_i
  @hits = api_response["HITS"].to_i
  @nfo = api_response["NFO"] == "yes"
  @weblink = api_response["WEBLINK"]
  @language = api_response["LANGUAGE"]
  @image_url = api_response["IMAGE"]
  @region = api_response["REGION"].to_i
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



13
14
15
# File 'lib/nzbmatrix/search_result.rb', line 13

def category
  @category
end

#commentsObject

Returns the value of attribute comments.



15
16
17
# File 'lib/nzbmatrix/search_result.rb', line 15

def comments
  @comments
end

#groupObject

Returns the value of attribute group.



14
15
16
# File 'lib/nzbmatrix/search_result.rb', line 14

def group
  @group
end

#hitsObject

Returns the value of attribute hits.



16
17
18
# File 'lib/nzbmatrix/search_result.rb', line 16

def hits
  @hits
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/nzbmatrix/search_result.rb', line 7

def id
  @id
end

#image_urlObject

Returns the value of attribute image_url.



19
20
21
# File 'lib/nzbmatrix/search_result.rb', line 19

def image_url
  @image_url
end

#index_dateObject

Returns the value of attribute index_date.



11
12
13
# File 'lib/nzbmatrix/search_result.rb', line 11

def index_date
  @index_date
end

#languageObject

Returns the value of attribute language.



18
19
20
# File 'lib/nzbmatrix/search_result.rb', line 18

def language
  @language
end

Returns the value of attribute link.



9
10
11
# File 'lib/nzbmatrix/search_result.rb', line 9

def link
  @link
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/nzbmatrix/search_result.rb', line 8

def name
  @name
end

#regionObject

Returns the value of attribute region.



20
21
22
# File 'lib/nzbmatrix/search_result.rb', line 20

def region
  @region
end

#sizeObject

Returns the value of attribute size.



10
11
12
# File 'lib/nzbmatrix/search_result.rb', line 10

def size
  @size
end

#usenet_dateObject

Returns the value of attribute usenet_date.



12
13
14
# File 'lib/nzbmatrix/search_result.rb', line 12

def usenet_date
  @usenet_date
end

Returns the value of attribute weblink.



17
18
19
# File 'lib/nzbmatrix/search_result.rb', line 17

def weblink
  @weblink
end

Instance Method Details

#download(path = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/nzbmatrix/search_result.rb', line 42

def download(path = nil)
  path ||= Dir.pwd
  path = File.expand_path(path)
  FileUtils.mkdir_p(path)
  
  nzb = @client.download(id)
  File.open(File.join(path, "#{name}.nzb"), "w") { |f| f.write(nzb) }

  id
end

#has_image?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/nzbmatrix/search_result.rb', line 57

def has_image?
  !!@image_url
end

#has_nfo?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/nzbmatrix/search_result.rb', line 53

def has_nfo?
  !!@nfo
end