Class: ContentGenerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/Rubbit/Rubbit_Objects.rb

Instance Method Summary collapse

Constructor Details

#initialize(source, limit = 100, after = '') ⇒ ContentGenerator

Returns a new instance of ContentGenerator.



83
84
85
86
87
88
89
90
# File 'lib/Rubbit/Rubbit_Objects.rb', line 83

def initialize(source,limit=100,after='')
  @source = source
  @limit = limit
  @count = 0
  @data = []
  @after = after
  @modhash = nil
end

Instance Method Details

#[](i) ⇒ Object



165
166
167
# File 'lib/Rubbit/Rubbit_Objects.rb', line 165

def [](i)
  return @data[i]
end

#eachObject



92
93
94
95
96
97
98
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/Rubbit/Rubbit_Objects.rb', line 92

def each
  index = 0
  if(@limit!=nil)
    listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
    if(listing.children[listing.children.length-1]!=nil)
      @after = listing.children[listing.children.length-1].name
    else
      @after = nil
    end
    if(@after == nil)
      @data+=[]
    else
      @data += listing.children
      @count += listing.children.length
    end
  else
    listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+100.to_s+"&after="+@after+"&count="+@count.to_s)
    if(listing.children[listing.children.length-1]!=nil)
      @after = listing.children[listing.children.length-1].name
    else
      @after = nil
    end
    if(@after == nil)
      @data+=[]
    else
      @data += listing.children
      @count+= listing.children.length
    end
  end
  
  while(index<@data.length)
    yield @data[index]
    index+=1
    if(index==@data.length)
      if(@after==nil)
        @after=''
      end
      if(@limit!=nil)
        if(@limit-@count>0)
          listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
          if(listing.children[listing.children.length-1]!=nil)
            @after = listing.children[listing.children.length-1].name
          else
            @after = nil
          end
          if(@after == nil)
            @data+=[]
          else
            @data += listing.children
            @count += listing.children.length
          end
        else
          @data += []
        end
      else
        listing = Rubbit_Object_Builder.instance.build_listing(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
        puts(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
        if(listing.children[listing.children.length-1]!=nil)
          @after = listing.children[listing.children.length-1].name
        else
          @after = nil
        end
        if(@after == nil)
          @data+=[]
        else
          @data += listing.children
          @count += listing.children.length
        end
      end
    end
  end
end

#lengthObject



169
170
171
# File 'lib/Rubbit/Rubbit_Objects.rb', line 169

def length
  return @data.length
end

#nextObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/Rubbit/Rubbit_Objects.rb', line 173

def next
  listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+1.to_s+"&after="+@after+"&count="+@count.to_s)
  if(listing.children[listing.children.length-1]!=nil)
    @after = listing.children[listing.children.length-1].name
  else
    @after = nil
  end
  if(@after == nil)
    @data+=[]
    return nil
  else
    @data += listing.children
    @count+= listing.children.length
    return listing.children[0]
  end
end