Class: ArchiveStorage::PlanResult
- Inherits:
-
Object
- Object
- ArchiveStorage::PlanResult
- Defined in:
- lib/archive_storage/plan_result.rb
Instance Attribute Summary collapse
-
#by_model ⇒ Object
readonly
Returns the value of attribute by_model.
-
#byte_size ⇒ Object
readonly
Returns the value of attribute byte_size.
-
#candidates ⇒ Object
readonly
Returns the value of attribute candidates.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#uploader_name ⇒ Object
Returns the value of attribute uploader_name.
Instance Method Summary collapse
- #add(candidate) ⇒ Object
-
#initialize(uploader_name: nil, destination: nil) ⇒ PlanResult
constructor
A new instance of PlanResult.
- #to_text ⇒ Object
Constructor Details
#initialize(uploader_name: nil, destination: nil) ⇒ PlanResult
Returns a new instance of PlanResult.
8 9 10 11 12 13 14 |
# File 'lib/archive_storage/plan_result.rb', line 8 def initialize(uploader_name: nil, destination: nil) @uploader_name = uploader_name @destination = destination @candidates = 0 @byte_size = 0 @by_model = Hash.new { |hash, key| hash[key] = { count: 0, byte_size: 0 } } end |
Instance Attribute Details
#by_model ⇒ Object (readonly)
Returns the value of attribute by_model.
6 7 8 |
# File 'lib/archive_storage/plan_result.rb', line 6 def by_model @by_model end |
#byte_size ⇒ Object (readonly)
Returns the value of attribute byte_size.
6 7 8 |
# File 'lib/archive_storage/plan_result.rb', line 6 def byte_size @byte_size end |
#candidates ⇒ Object (readonly)
Returns the value of attribute candidates.
6 7 8 |
# File 'lib/archive_storage/plan_result.rb', line 6 def candidates @candidates end |
#destination ⇒ Object
Returns the value of attribute destination.
5 6 7 |
# File 'lib/archive_storage/plan_result.rb', line 5 def destination @destination end |
#uploader_name ⇒ Object
Returns the value of attribute uploader_name.
5 6 7 |
# File 'lib/archive_storage/plan_result.rb', line 5 def uploader_name @uploader_name end |
Instance Method Details
#add(candidate) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/archive_storage/plan_result.rb', line 16 def add(candidate) @candidates += 1 @byte_size += candidate.byte_size.to_i row = by_model[candidate.record.class.name] row[:count] += 1 row[:byte_size] += candidate.byte_size.to_i end |
#to_text ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/archive_storage/plan_result.rb', line 24 def to_text lines = [] lines << "ArchiveStorage Migration Plan" lines << "" lines << "Uploader: #{uploader_name || "all registered uploaders"}" lines << "Candidates: #{candidates}" lines << "Estimated size: #{format_bytes(byte_size)}" lines << "" if by_model.any? lines << "By model:" by_model.each do |model, stats| lines << "- #{model}: #{stats[:count]} files, #{format_bytes(stats[:byte_size])}" end lines << "" end lines << "Destination: #{destination}" if destination lines << "No files were moved." lines.join("\n") end |