Class: S3::ListBucketParser

Inherits:
Object
  • Object
show all
Defined in:
lib/s3-ruby.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.



476
477
478
# File 'lib/s3-ruby.rb', line 476

def initialize
  reset
end

Instance Attribute Details

#common_prefixesObject (readonly)

Returns the value of attribute common_prefixes.



474
475
476
# File 'lib/s3-ruby.rb', line 474

def common_prefixes
  @common_prefixes
end

#entriesObject (readonly)

Returns the value of attribute entries.



473
474
475
# File 'lib/s3-ruby.rb', line 473

def entries
  @entries
end

#propertiesObject (readonly)

Returns the value of attribute properties.



472
473
474
# File 'lib/s3-ruby.rb', line 472

def properties
  @properties
end

Instance Method Details

#resetObject

get ready for another parse



544
545
546
547
548
549
550
551
# File 'lib/s3-ruby.rb', line 544

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



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/s3-ruby.rb', line 493

def tag_end(name)
  # this prefix is the one we echo back from the request
  if name == 'Name'
    @properties.name = @curr_text
  elsif name == 'Prefix' && @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



480
481
482
483
484
485
486
487
488
489
490
# File 'lib/s3-ruby.rb', line 480

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



535
536
537
# File 'lib/s3-ruby.rb', line 535

def text(text)
    @curr_text += text
end

#xmldecl(version, encoding, standalone) ⇒ Object



539
540
541
# File 'lib/s3-ruby.rb', line 539

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