Class: Miteru::Kit
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Service
#call, call, #result, result
Constructor Details
#initialize(url, source:) ⇒ Kit
Returns a new instance of Kit.
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/miteru/kit.rb', line 27
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?
15
16
17
|
# File 'lib/miteru/kit.rb', line 15
def content_length
@content_length
end
|
21
22
23
|
# File 'lib/miteru/kit.rb', line 21
def
@headers
end
|
#mime_type ⇒ String?
18
19
20
|
# File 'lib/miteru/kit.rb', line 18
def mime_type
@mime_type
end
|
#source ⇒ String
9
10
11
|
# File 'lib/miteru/kit.rb', line 9
def source
@source
end
|
#status ⇒ Integer?
12
13
14
|
# File 'lib/miteru/kit.rb', line 12
def status
@status
end
|
#url ⇒ String
6
7
8
|
# File 'lib/miteru/kit.rb', line 6
def url
@url
end
|
Instance Method Details
#basename ⇒ Object
51
52
53
|
# File 'lib/miteru/kit.rb', line 51
def basename
@basename ||= File.basename(url)
end
|
#decoded_url ⇒ Object
88
89
90
|
# File 'lib/miteru/kit.rb', line 88
def decoded_url
@decoded_url ||= URI.decode_www_form_component(url)
end
|
#downloaded? ⇒ Boolean
63
64
65
|
# File 'lib/miteru/kit.rb', line 63
def downloaded?
File.exist?(filepath_to_download)
end
|
#extname ⇒ Object
45
46
47
48
49
|
# File 'lib/miteru/kit.rb', line 45
def extname
return ".tar.gz" if url.end_with?("tar.gz")
File.extname(url)
end
|
#filename ⇒ Object
55
56
57
|
# File 'lib/miteru/kit.rb', line 55
def filename
@filename ||= CGI.unescape(basename)
end
|
#filename_with_size ⇒ Object
73
74
75
76
77
78
|
# File 'lib/miteru/kit.rb', line 73
def filename_with_size
return filename unless filesize
kb = (filesize.to_f / 1024.0).ceil
"#{filename}(#{kb}KB)"
end
|
#filepath_to_download ⇒ Object
59
60
61
|
# File 'lib/miteru/kit.rb', line 59
def filepath_to_download
"#{base_dir}/#{filename_to_download}"
end
|
#filesize ⇒ Object
67
68
69
70
71
|
# File 'lib/miteru/kit.rb', line 67
def filesize
return nil unless downloaded?
File.size filepath_to_download
end
|
#hostname ⇒ Object
84
85
86
|
# File 'lib/miteru/kit.rb', line 84
def hostname
@hostname ||= URI(url).hostname
end
|
#id ⇒ Object
80
81
82
|
# File 'lib/miteru/kit.rb', line 80
def id
@id ||= UUIDTools::UUID.random_create.to_s
end
|
#truncated_url ⇒ String
95
96
97
|
# File 'lib/miteru/kit.rb', line 95
def truncated_url
url.truncate(64)
end
|
#valid? ⇒ Boolean
39
40
41
42
43
|
# File 'lib/miteru/kit.rb', line 39
def valid?
before_validation
valid_ext? && reachable? && valid_mime_type? && valid_content_length?
end
|