Class: TestServer::UploadedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/test_server/uploaded_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checksumObject

Returns the value of attribute checksum.



10
11
12
# File 'lib/test_server/uploaded_file.rb', line 10

def checksum
  @checksum
end

#filetypeObject

Returns the value of attribute filetype.



10
11
12
# File 'lib/test_server/uploaded_file.rb', line 10

def filetype
  @filetype
end

#virus_idObject

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

Returns:

  • (Boolean)


38
39
40
# File 'lib/test_server/uploaded_file.rb', line 38

def contains_virus?
  !virus_id.blank?
end

#has_checksum?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/test_server/uploaded_file.rb', line 42

def has_checksum?
  !checksum.blank?
end

#has_filetype?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/test_server/uploaded_file.rb', line 34

def has_filetype?
  !filetype.blank?
end

#nameObject



30
31
32
# File 'lib/test_server/uploaded_file.rb', line 30

def name
  File.basename(uploaded_file.original_filename.to_s)
end

#pathObject



26
27
28
# File 'lib/test_server/uploaded_file.rb', line 26

def path
  uploaded_file.path.to_s
end

#sizeObject



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