Class: TestServer::UploadedFile
- Inherits:
-
Object
- Object
- TestServer::UploadedFile
- Defined in:
- lib/test_server/uploaded_file.rb
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#filetype ⇒ Object
Returns the value of attribute filetype.
-
#virus_id ⇒ Object
Returns the value of attribute virus_id.
Instance Method Summary collapse
- #contains_virus? ⇒ Boolean
- #has_checksum? ⇒ Boolean
- #has_filetype? ⇒ Boolean
-
#initialize(uploaded_file) ⇒ UploadedFile
constructor
A new instance of UploadedFile.
- #name ⇒ Object
- #path ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(uploaded_file) ⇒ UploadedFile
Returns a new instance of UploadedFile.
12 13 14 15 16 17 18 19 20 |
# File 'lib/test_server/uploaded_file.rb', line 12 def initialize(uploaded_file) if uploaded_file.respond_to? :tempfile @uploaded_file = uploaded_file else @uploaded_file = OpenStruct.new end @checksum = [] end |
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
10 11 12 |
# File 'lib/test_server/uploaded_file.rb', line 10 def checksum @checksum end |
#filetype ⇒ Object
Returns the value of attribute filetype.
10 11 12 |
# File 'lib/test_server/uploaded_file.rb', line 10 def filetype @filetype end |
#virus_id ⇒ Object
Returns the value of attribute virus_id.
10 11 12 |
# File 'lib/test_server/uploaded_file.rb', line 10 def virus_id @virus_id end |
Instance Method Details
#contains_virus? ⇒ Boolean
38 39 40 |
# File 'lib/test_server/uploaded_file.rb', line 38 def contains_virus? !virus_id.blank? end |
#has_checksum? ⇒ Boolean
42 43 44 |
# File 'lib/test_server/uploaded_file.rb', line 42 def has_checksum? !checksum.blank? end |
#has_filetype? ⇒ Boolean
34 35 36 |
# File 'lib/test_server/uploaded_file.rb', line 34 def has_filetype? !filetype.blank? end |
#name ⇒ Object
30 31 32 |
# File 'lib/test_server/uploaded_file.rb', line 30 def name File.basename(uploaded_file.original_filename.to_s) end |
#path ⇒ Object
26 27 28 |
# File 'lib/test_server/uploaded_file.rb', line 26 def path uploaded_file.path.to_s end |
#size ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/test_server/uploaded_file.rb', line 46 def size formula = lambda { |number| uploaded_file.size.to_f / (2**number) } result = {} result[:b] = FileSize.new(suffix: 'B', value: uploaded_file.size.to_s) result[:kib] = FileSize.new(suffix: 'KiB', value: '%.2f' % formula.call(10)) result[:mib] = FileSize.new(suffix: 'MiB', value: '%.2f' % formula.call(20)) result[:gib] = FileSize.new(suffix: 'KiB', value: '%.2f' % formula.call(30)) result end |