Class: Dratools::DownloadCandidate
- Inherits:
-
Object
- Object
- Dratools::DownloadCandidate
- 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
-
#ftp_url ⇒ Object
readonly
Returns the value of attribute ftp_url.
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#run_accession ⇒ Object
readonly
Returns the value of attribute run_accession.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #directory_url_for_protocol?(protocol = HTTPS_PROTOCOL) ⇒ Boolean
- #filename_for_protocol(protocol = HTTPS_PROTOCOL) ⇒ Object
-
#initialize(type:, run_accession: nil, url: nil, ftp_url: nil, size: nil, md5: nil) ⇒ DownloadCandidate
constructor
A new instance of DownloadCandidate.
- #url_for_protocol(protocol) ⇒ Object
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_url ⇒ Object (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 |
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
15 16 17 |
# File 'lib/dratools/download_candidate.rb', line 15 def md5 @md5 end |
#run_accession ⇒ Object (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 |
#size ⇒ Object (readonly)
Returns the value of attribute size.
15 16 17 |
# File 'lib/dratools/download_candidate.rb', line 15 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/dratools/download_candidate.rb', line 15 def type @type end |
#url ⇒ Object (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
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 |