Class: Aspera::Cli::Result::ObjectList
- Inherits:
-
Result
- Object
- Result
- Aspera::Cli::Result::ObjectList
- Defined in:
- lib/aspera/cli/result.rb
Overview
Note:
The total parameter is used to display pagination information (e.g., "Items: 10/100")
Object list result (Array of Hash)
Instance Attribute Summary collapse
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #format(formatter) ⇒ Object
-
#initialize(data, fields: nil, total: nil) ⇒ ObjectList
constructor
A new instance of ObjectList.
Constructor Details
#initialize(data, fields: nil, total: nil) ⇒ ObjectList
Returns a new instance of ObjectList.
236 237 238 239 240 241 242 |
# File 'lib/aspera/cli/result.rb', line 236 def initialize(data, fields: nil, total: nil) Aspera.assert_type(data, Array){'object list result data'} raise ArgumentError, 'Object list result requires Array of Hash' unless data.all?(Hash) Aspera.assert_type(total, Integer, NilClass){'total'} super(data: data, fields: fields) @total = total end |
Instance Attribute Details
#total ⇒ Object (readonly)
Returns the value of attribute total.
231 232 233 |
# File 'lib/aspera/cli/result.rb', line 231 def total @total end |
Instance Method Details
#format(formatter) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/aspera/cli/result.rb', line 244 def format(formatter) formatter.display_item_count(@data.length, @total) case formatter.format_type when :image # Extract single field for image display Aspera.assert(@data.length == 1, 'image display requires a single result', type: Cli::BadArgument) SingleObject.new(@data.first).format(formatter) when :table, :csv Aspera.assert_array_all(@data, Hash){'result'} data = formatter.flat_hash? ? @data.map{ |obj| DotContainer.new(obj).to_dotted} : @data formatter.display_table(data, formatter.compute_fields(data, @fields), single: false) else super end end |