Class: GRI::LocalLDB
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #get_after(data_name, time, pos = 0) ⇒ Object
- #get_data_names ⇒ Object
- #getl_after(data_name, time, pos = 0) ⇒ Object
-
#initialize(dir) ⇒ LocalLDB
constructor
A new instance of LocalLDB.
- #open_after(data_name, time, pos = 0) ⇒ Object
Constructor Details
#initialize(dir) ⇒ LocalLDB
Returns a new instance of LocalLDB.
10 11 12 |
# File 'lib/gri/ldb.rb', line 10 def initialize dir @dir = dir end |
Class Method Details
.get_gritab_lines(path) ⇒ Object
6 7 8 |
# File 'lib/gri/ldb.rb', line 6 def self.get_gritab_lines path lines = File.readlines path end |
Instance Method Details
#close ⇒ Object
60 61 |
# File 'lib/gri/ldb.rb', line 60 def close end |
#get_after(data_name, time, pos = 0) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/gri/ldb.rb', line 14 def get_after data_name, time, pos=0 open_after(data_name, time) {|t, line, pos| h = LTSV.parse_string line yield t, h, pos } end |
#get_data_names ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/gri/ldb.rb', line 52 def get_data_names Dir.glob("#{@dir}/*_*").inject({}) {|h, path| data_name, interval = File.basename(path).split /_/ h[data_name || ''] = (interval || 300).to_i h } end |
#getl_after(data_name, time, pos = 0) ⇒ Object
21 22 23 24 25 |
# File 'lib/gri/ldb.rb', line 21 def getl_after data_name, time, pos=0 open_after(data_name, time, pos) {|t, line, pos2| yield t, line, pos2 } end |
#open_after(data_name, time, pos = 0) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gri/ldb.rb', line 27 def open_after data_name, time, pos=0 ymd = time.strftime '%Y%m%d' pat = "#{@dir}/#{data_name}_*/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" for ymd_file in Dir.glob(pat).sort vymd = File.basename ymd_file if vymd >= ymd rtime = Time.local(vymd[0, 4], vymd[4, 2], vymd[6, 2]) open(ymd_file, 'rb') {|f| pos = 0 if f.stat.size < pos f.pos = pos while line = f.gets pos += line.size line.chomp! tstr = line.scan(/\b_time:(\d+)\b/).first.first rescue nil t = Time.at(tstr.to_i) if t > time yield t, line, pos end end pos = 0 } end end end |