Class: SdbDal::S3::ListBucketParser

Inherits:
Object
  • Object
show all
Defined in:
lib/sdb_dal/s3.rb

Overview

Parses the list bucket output into a list of ListEntry objects, and a list of CommonPrefixEntry objects if applicable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListBucketParser

Returns a new instance of ListBucketParser.



407
408
409
# File 'lib/sdb_dal/s3.rb', line 407

def initialize
  reset
end

Instance Attribute Details

#common_prefixesObject (readonly)

Returns the value of attribute common_prefixes.



405
406
407
# File 'lib/sdb_dal/s3.rb', line 405

def common_prefixes
  @common_prefixes
end

#entriesObject (readonly)

Returns the value of attribute entries.



404
405
406
# File 'lib/sdb_dal/s3.rb', line 404

def entries
  @entries
end

#propertiesObject (readonly)

Returns the value of attribute properties.



403
404
405
# File 'lib/sdb_dal/s3.rb', line 403

def properties
  @properties
end

Instance Method Details

#resetObject

get ready for another parse



476
477
478
479
480
481
482
483
# File 'lib/sdb_dal/s3.rb', line 476

def reset
  @is_echoed_prefix = true;
  @entries = []
  @curr_entry = nil
  @common_prefixes = []
  @common_prefix_entry = nil
  @curr_text = ''
end

#tag_end(name) ⇒ Object

we have one, add him to the entries list



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/sdb_dal/s3.rb', line 424

def tag_end(name)
  # this prefix is the one we echo back from the request
  # this prefix is the one we echo back from the request
  if name == 'Name'
    @properties.name = @curr_text
  elsif name == 'Prefix' and @is_echoed_prefix
    @properties.prefix = @curr_text
    @is_echoed_prefix = nil
  elsif name == 'Marker'
    @properties.marker = @curr_text
  elsif name == 'MaxKeys'
    @properties.max_keys = @curr_text.to_i
  elsif name == 'Delimiter'
    @properties.delimiter = @curr_text
  elsif name == 'IsTruncated'
    @properties.is_truncated = @curr_text == 'true'
  elsif name == 'NextMarker'
    @properties.next_marker = @curr_text
  elsif name == 'Contents'
    @entries << @curr_entry
  elsif name == 'Key'
    @curr_entry.key = @curr_text
  elsif name == 'LastModified'
    @curr_entry.last_modified = @curr_text
  elsif name == 'ETag'
    @curr_entry.etag = @curr_text
  elsif name == 'Size'
    @curr_entry.size = @curr_text.to_i
  elsif name == 'StorageClass'
    @curr_entry.storage_class = @curr_text
  elsif name == 'ID'
    @curr_entry.owner.id = @curr_text
  elsif name == 'DisplayName'
    @curr_entry.owner.display_name = @curr_text
  elsif name == 'CommonPrefixes'
    @common_prefixes << @common_prefix_entry
  elsif name == 'Prefix'
    # this is the common prefix for keys that match up to the delimiter
    @common_prefix_entry.prefix = @curr_text
  end
  @curr_text = ''
end

#tag_start(name, attributes) ⇒ Object



411
412
413
414
415
416
417
418
419
420
421
# File 'lib/sdb_dal/s3.rb', line 411

def tag_start(name, attributes)
  if name == 'ListBucketResult'
    @properties = ListProperties.new
  elsif name == 'Contents'
    @curr_entry = ListEntry.new
  elsif name == 'Owner'
    @curr_entry.owner = Owner.new
  elsif name == 'CommonPrefixes'
    @common_prefix_entry = CommonPrefixEntry.new
  end
end

#text(text) ⇒ Object



467
468
469
# File 'lib/sdb_dal/s3.rb', line 467

def text(text)
    @curr_text += text
end

#xmldecl(version, encoding, standalone) ⇒ Object



471
472
473
# File 'lib/sdb_dal/s3.rb', line 471

def xmldecl(version, encoding, standalone)
  # ignore
end