Class: Awsum::S3::ObjectParser

Inherits:
Parser show all
Defined in:
lib/awsum/s3/object.rb

Overview

TODO: Create a more advanced array which can deal with pagination

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(s3) ⇒ ObjectParser

:nodoc:



72
73
74
75
76
77
78
# File 'lib/awsum/s3/object.rb', line 72

def initialize(s3)
  @s3 = s3
  @bucket = ''
  @objects = []
  @text = nil
  @stack = []
end

Instance Method Details

#resultObject



133
134
135
# File 'lib/awsum/s3/object.rb', line 133

def result
  @objects
end

#tag_end(tag) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/awsum/s3/object.rb', line 99

def tag_end(tag)
  case tag
    when 'Name'
      if @stack[-1] == 'ListBucketResult'
        @bucket = @text.strip
      end
    when 'Contents'
      @objects << Object.new(
                    @s3,
                    @bucket,
                    @current['Key'],
                    Time.parse(@current['LastModified']),
                    @current['ETag'],
                    @current['Size'].to_i,
                    {'id' => @owner['ID'], 'name' => @owner['DisplayName']},
                    @current['StorageClass']
                  )
      @current = nil
      @text = nil
      @stack.pop
    when 'Owner'
      @stack.pop
    else
      text = @text.strip unless @text.nil?
      case @stack[-1]
        when 'Owner'
          @owner[tag] = (text == '' ? nil : text) unless @owner.nil?
        when 'Contents'
          @current[tag] = (text == '' ? nil : text) unless @current.nil?
      end
      @text = ''
  end
end

#tag_start(tag, attributes) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/awsum/s3/object.rb', line 80

def tag_start(tag, attributes)
  case tag
    when 'ListBucketResult'
      @stack << tag
      @text = ''
    when 'Contents'
      @stack << tag
      @current = {}
      @text = ''
    when 'Owner'
      @owner = {}
      @stack << tag
  end
end

#text(text) ⇒ Object



95
96
97
# File 'lib/awsum/s3/object.rb', line 95

def text(text)
  @text << text unless @text.nil?
end