Class: S3::ListBucketParser

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



524
525
526
# File 'lib/S3.rb', line 524

def initialize
  reset
end

Instance Attribute Details

#common_prefixesObject (readonly)

Returns the value of attribute common_prefixes.



522
523
524
# File 'lib/S3.rb', line 522

def common_prefixes
  @common_prefixes
end

#entriesObject (readonly)

Returns the value of attribute entries.



521
522
523
# File 'lib/S3.rb', line 521

def entries
  @entries
end

#propertiesObject (readonly)

Returns the value of attribute properties.



520
521
522
# File 'lib/S3.rb', line 520

def properties
  @properties
end

Instance Method Details

#resetObject

get ready for another parse



594
595
596
597
598
599
600
601
# File 'lib/S3.rb', line 594

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



541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/S3.rb', line 541

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' 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 = Owner.new if !@curr_entry.owner
    @curr_entry.owner.id = @curr_text
  elsif name == 'DisplayName'
    @curr_entry.owner = Owner.new if !@curr_entry.owner
    @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



528
529
530
531
532
533
534
535
536
537
538
# File 'lib/S3.rb', line 528

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



585
586
587
# File 'lib/S3.rb', line 585

def text(text)
    @curr_text += text
end

#xmldecl(version, encoding, standalone) ⇒ Object



589
590
591
# File 'lib/S3.rb', line 589

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