Class: Miteru::Kit
Instance Attribute Summary collapse
Instance Method Summary
collapse
#decoded_url, #defanged_truncated_url, #truncated_url
Methods inherited from Service
#call, call, #result, result
Constructor Details
#initialize(url, source:) ⇒ Kit
Returns a new instance of Kit.
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/miteru/kit.rb', line 29
def initialize(url, source:)
super()
@url = url
@source = source
@content_length = nil
@mime_type = nil
@status = nil
@headers = nil
end
|
Instance Attribute Details
#content_length ⇒ Integer?
17
18
19
|
# File 'lib/miteru/kit.rb', line 17
def content_length
@content_length
end
|
23
24
25
|
# File 'lib/miteru/kit.rb', line 23
def
@headers
end
|
#mime_type ⇒ String?
20
21
22
|
# File 'lib/miteru/kit.rb', line 20
def mime_type
@mime_type
end
|
#source ⇒ String
11
12
13
|
# File 'lib/miteru/kit.rb', line 11
def source
@source
end
|
#status ⇒ Integer?
14
15
16
|
# File 'lib/miteru/kit.rb', line 14
def status
@status
end
|
#url ⇒ String
8
9
10
|
# File 'lib/miteru/kit.rb', line 8
def url
@url
end
|
Instance Method Details
#basename ⇒ Object
53
54
55
|
# File 'lib/miteru/kit.rb', line 53
def basename
@basename ||= File.basename(url)
end
|
#downloaded? ⇒ Boolean
65
66
67
|
# File 'lib/miteru/kit.rb', line 65
def downloaded?
File.exist?(filepath_to_download)
end
|
#extname ⇒ Object
47
48
49
50
51
|
# File 'lib/miteru/kit.rb', line 47
def extname
return ".tar.gz" if url.end_with?("tar.gz")
File.extname(url)
end
|
#filename ⇒ Object
57
58
59
|
# File 'lib/miteru/kit.rb', line 57
def filename
@filename ||= CGI.unescape(basename)
end
|
#filename_with_size ⇒ Object
75
76
77
78
79
|
# File 'lib/miteru/kit.rb', line 75
def filename_with_size
return filename unless filesize
"#{filename} (#{Helpers.number_to_human_size(filesize)})"
end
|
#filepath_to_download ⇒ Object
61
62
63
|
# File 'lib/miteru/kit.rb', line 61
def filepath_to_download
"#{base_dir}/#{filename_to_download}"
end
|
#filesize ⇒ Object
69
70
71
72
73
|
# File 'lib/miteru/kit.rb', line 69
def filesize
return nil unless downloaded?
File.size filepath_to_download
end
|
#hostname ⇒ Object
85
86
87
|
# File 'lib/miteru/kit.rb', line 85
def hostname
@hostname ||= URI(url).hostname
end
|
#id ⇒ Object
81
82
83
|
# File 'lib/miteru/kit.rb', line 81
def id
@id ||= UUIDTools::UUID.random_create.to_s
end
|
#valid? ⇒ Boolean
41
42
43
44
45
|
# File 'lib/miteru/kit.rb', line 41
def valid?
before_validation
valid_ext? && reachable? && valid_mime_type? && valid_content_length?
end
|