Class: Miteru::Kit

Inherits:
Object
  • Object
show all
Defined in:
lib/miteru/kit.rb

Constant Summary collapse

VALID_EXTENSIONS =
[".zip", ".rar", ".7z", ".tar", ".gz"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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_urlObject (readonly)

Returns the value of attribute base_url.



10
11
12
# File 'lib/miteru/kit.rb', line 10

def base_url
  @base_url
end

Returns the value of attribute link.



10
11
12
# File 'lib/miteru/kit.rb', line 10

def link
  @link
end

Instance Method Details

#basenameObject



27
28
29
# File 'lib/miteru/kit.rb', line 27

def basename
  File.basename(link)
end

#download_filepathObject



39
40
41
# File 'lib/miteru/kit.rb', line 39

def download_filepath
  "#{base_dir}/#{download_filename}"
end

#extnameObject



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

#filenameObject



31
32
33
# File 'lib/miteru/kit.rb', line 31

def filename
  CGI.unescape basename
end

#filename_with_sizeObject



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

#filesizeObject



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

#urlObject



35
36
37
# File 'lib/miteru/kit.rb', line 35

def url
  "#{base_url}/#{basename}"
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/miteru/kit.rb', line 17

def valid?
  VALID_EXTENSIONS.include? extname
end