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.
238 239 240 241 242 243 |
# File 'lib/aspera/cli/result.rb', line 238 def initialize(data, fields: nil, total: nil) Aspera.assert_array_all(data, Hash, type: ArgumentError){'object list result data'} 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.
233 234 235 |
# File 'lib/aspera/cli/result.rb', line 233 def total @total end |
Instance Method Details
#format(formatter) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/aspera/cli/result.rb', line 245 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 |