Class: Miteru::Kit
- Inherits:
-
Object
- Object
- Miteru::Kit
- Defined in:
- lib/miteru/kit.rb
Constant Summary collapse
- VALID_EXTENSIONS =
[".zip", ".rar", ".7z", ".tar", ".gz"].freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
Instance Method Summary collapse
- #basename ⇒ Object
- #download_filepath ⇒ Object
- #extname ⇒ Object
- #filename ⇒ Object
- #filename_with_size ⇒ Object
- #filesize ⇒ Object
-
#initialize(base_url:, link:) ⇒ Kit
constructor
A new instance of Kit.
- #url ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(base_url:, link:) ⇒ Kit
Returns a new instance of Kit.
12 13 14 15 |
# File 'lib/miteru/kit.rb', line 12 def initialize(base_url:, link:) @base_url = base_url @link = link.start_with?("/") ? link[1..-1] : link end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
10 11 12 |
# File 'lib/miteru/kit.rb', line 10 def base_url @base_url end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
10 11 12 |
# File 'lib/miteru/kit.rb', line 10 def link @link end |
Instance Method Details
#basename ⇒ Object
27 28 29 |
# File 'lib/miteru/kit.rb', line 27 def basename File.basename(link) end |
#download_filepath ⇒ Object
39 40 41 |
# File 'lib/miteru/kit.rb', line 39 def download_filepath "#{base_dir}/#{download_filename}" end |
#extname ⇒ Object
21 22 23 24 25 |
# File 'lib/miteru/kit.rb', line 21 def extname return ".tar.gz" if link.end_with?("tar.gz") File.extname(link) end |
#filename ⇒ Object
31 32 33 |
# File 'lib/miteru/kit.rb', line 31 def filename CGI.unescape basename end |
#filename_with_size ⇒ Object
49 50 51 52 53 |
# File 'lib/miteru/kit.rb', line 49 def filename_with_size return filename unless filesize "#{filename}(#{filesize / 1024}KB)" end |
#filesize ⇒ Object
43 44 45 46 47 |
# File 'lib/miteru/kit.rb', line 43 def filesize return nil unless File.exist?(download_filepath) File.size download_filepath end |
#url ⇒ Object
35 36 37 |
# File 'lib/miteru/kit.rb', line 35 def url "#{base_url}/#{basename}" end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/miteru/kit.rb', line 17 def valid? VALID_EXTENSIONS.include? extname end |