Class: Miteru::Kit
- Inherits:
-
Object
- Object
- Miteru::Kit
- Defined in:
- lib/miteru/kit.rb
Constant Summary collapse
- VALID_EXTENSIONS =
Miteru.configuration.valid_extensions
- VALID_MIME_TYPES =
Miteru.configuration.valid_mime_types
Instance Attribute Summary collapse
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #basename ⇒ Object
- #decoded_url ⇒ Object
- #downloaded? ⇒ Boolean
- #extname ⇒ Object
- #filename ⇒ Object
- #filename_with_size ⇒ Object
- #filepath_to_download ⇒ Object
- #filesize ⇒ Object
- #hostname ⇒ Object
- #id ⇒ Object
-
#initialize(url) ⇒ Kit
constructor
A new instance of Kit.
- #valid? ⇒ Boolean
Constructor Details
#initialize(url) ⇒ Kit
Returns a new instance of Kit.
14 15 16 17 18 19 20 21 |
# File 'lib/miteru/kit.rb', line 14 def initialize(url) @url = url @content_length = nil @mime_type = nil @status = nil @headers = nil end |
Instance Attribute Details
#content_length ⇒ Object (readonly)
Returns the value of attribute content_length.
12 13 14 |
# File 'lib/miteru/kit.rb', line 12 def content_length @content_length end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/miteru/kit.rb', line 12 def headers @headers end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
12 13 14 |
# File 'lib/miteru/kit.rb', line 12 def mime_type @mime_type end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/miteru/kit.rb', line 12 def status @status end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/miteru/kit.rb', line 12 def url @url end |
Instance Method Details
#basename ⇒ Object
36 37 38 |
# File 'lib/miteru/kit.rb', line 36 def basename @basename ||= File.basename(url) end |
#decoded_url ⇒ Object
73 74 75 |
# File 'lib/miteru/kit.rb', line 73 def decoded_url @decoded_url ||= URI.decode_www_form_component(url) end |
#downloaded? ⇒ Boolean
48 49 50 |
# File 'lib/miteru/kit.rb', line 48 def downloaded? File.exist?(filepath_to_download) end |
#extname ⇒ Object
30 31 32 33 34 |
# File 'lib/miteru/kit.rb', line 30 def extname return ".tar.gz" if url.end_with?("tar.gz") File.extname(url) end |
#filename ⇒ Object
40 41 42 |
# File 'lib/miteru/kit.rb', line 40 def filename @filename ||= CGI.unescape(basename) end |
#filename_with_size ⇒ Object
58 59 60 61 62 63 |
# File 'lib/miteru/kit.rb', line 58 def filename_with_size return filename unless filesize kb = (filesize.to_f / 1024.0).ceil "#{filename}(#{kb}KB)" end |
#filepath_to_download ⇒ Object
44 45 46 |
# File 'lib/miteru/kit.rb', line 44 def filepath_to_download "#{base_dir}/#{filename_to_download}" end |
#filesize ⇒ Object
52 53 54 55 56 |
# File 'lib/miteru/kit.rb', line 52 def filesize return nil unless downloaded? File.size filepath_to_download end |
#hostname ⇒ Object
69 70 71 |
# File 'lib/miteru/kit.rb', line 69 def hostname @hostname ||= URI(url).hostname end |
#id ⇒ Object
65 66 67 |
# File 'lib/miteru/kit.rb', line 65 def id @id ||= UUIDTools::UUID.random_create.to_s end |
#valid? ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/miteru/kit.rb', line 23 def valid? # make a HEAD request for the validation before_validation valid_ext? && reachable? && valid_mime_type? && valid_content_length? end |