Class: Dratools::DownloadCandidate

Inherits:
Object
  • Object
show all
Defined in:
lib/dratools/download_candidate.rb

Overview

1 件のダウンロード候補を表す値オブジェクト。

Constant Summary collapse

FTP_PROTOCOL =
'ftp'
HTTPS_PROTOCOL =
'https'
HTTP_PROTOCOL =
'http'
HTTP_BASED_PROTOCOLS =
[HTTPS_PROTOCOL, HTTP_PROTOCOL].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, run_accession: nil, url: nil, ftp_url: nil, size: nil, md5: nil) ⇒ DownloadCandidate

Returns a new instance of DownloadCandidate.



17
18
19
20
21
22
23
24
# File 'lib/dratools/download_candidate.rb', line 17

def initialize(type:, run_accession: nil, url: nil, ftp_url: nil, size: nil, md5: nil)
  @run_accession = run_accession
  @type = type
  @url = url
  @ftp_url = ftp_url
  @size = size
  @md5 = md5
end

Instance Attribute Details

#ftp_urlObject (readonly)

Returns the value of attribute ftp_url.



15
16
17
# File 'lib/dratools/download_candidate.rb', line 15

def ftp_url
  @ftp_url
end

#md5Object (readonly)

Returns the value of attribute md5.



15
16
17
# File 'lib/dratools/download_candidate.rb', line 15

def md5
  @md5
end

#run_accessionObject (readonly)

Returns the value of attribute run_accession.



15
16
17
# File 'lib/dratools/download_candidate.rb', line 15

def run_accession
  @run_accession
end

#sizeObject (readonly)

Returns the value of attribute size.



15
16
17
# File 'lib/dratools/download_candidate.rb', line 15

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/dratools/download_candidate.rb', line 15

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



15
16
17
# File 'lib/dratools/download_candidate.rb', line 15

def url
  @url
end

Instance Method Details

#directory_url_for_protocol?(protocol = HTTPS_PROTOCOL) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/dratools/download_candidate.rb', line 41

def directory_url_for_protocol?(protocol = HTTPS_PROTOCOL)
  URI(url_for_protocol(protocol)).path.end_with?('/')
end

#filename_for_protocol(protocol = HTTPS_PROTOCOL) ⇒ Object



37
38
39
# File 'lib/dratools/download_candidate.rb', line 37

def filename_for_protocol(protocol = HTTPS_PROTOCOL)
  File.basename(URI(url_for_protocol(protocol)).path)
end

#url_for_protocol(protocol) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/dratools/download_candidate.rb', line 26

def url_for_protocol(protocol)
  case protocol.to_s
  when FTP_PROTOCOL
    ftp_url || url
  when *HTTP_BASED_PROTOCOLS
    url || ftp_url
  else
    raise InvalidProtocolError, "unknown protocol: #{protocol}"
  end
end