Class: JIJI::Dao::TimedDataIterator

Inherits:
Iterator
  • Object
show all
Defined in:
lib/jiji/dao/timed_data_dao.rb

Overview

複数のCSVファイルのデータを順番に読み込む。

Instance Method Summary collapse

Methods inherited from Iterator

#each

Constructor Details

#initialize(scale, start_time, end_time, dao) ⇒ TimedDataIterator

Returns a new instance of TimedDataIterator.



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/jiji/dao/timed_data_dao.rb', line 197

def initialize( scale, start_time, end_time, dao )
  super()
  @dao = dao
  @start_time = start_time
  @end_time = end_time
  @scale = scale
  @current = start_time
  @current_date = Date.new( @current.year, @current.mon, \
    TimedDataDao.dairy?(@scale)  ? @current.day : 1 )
  next_iterator
end

Instance Method Details

#closeObject



218
219
220
# File 'lib/jiji/dao/timed_data_dao.rb', line 218

def close
  @it.close if @it
end

#nextObject



211
212
213
214
215
216
217
# File 'lib/jiji/dao/timed_data_dao.rb', line 211

def next
  begin
    @it.next
  ensure
    next_iterator unless @it.next?
  end
end

#next?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/jiji/dao/timed_data_dao.rb', line 208

def next?
  @it && @it.next?
end

#next_iteratorObject



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/jiji/dao/timed_data_dao.rb', line 221

def next_iterator
  @it.close if @it
  @it = nil
  while ( @current.to_f <= @end_time.to_f )
    begin
      it = @dao.each_dairy_data( @scale, @current, @start_time, @end_time)
      if it != nil && it.next?
        @it = it
        return
      else
        it.close
      end
    ensure
      @current_date = TimedDataDao.dairy?(@scale) ? @current_date+1 : @current_date >> 1
      @current = Time.local(@current_date.year, @current_date.mon, @current_date.day)
    end
  end
end