Module: GHAUtils

Included in:
GHADownloader, GHAProvider
Defined in:
lib/gh-archive.rb

Instance Method Summary collapse

Instance Method Details

#each_time(from, to) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/gh-archive.rb', line 39

def each_time(from, to)
    current_time = from
    while current_time < to
        yield current_time
        current_time += 3600
    end
end

#get_gha_filename(date) ⇒ Object



11
12
13
# File 'lib/gh-archive.rb', line 11

def get_gha_filename(date)
    return ("%04d-%02d-%02d-%d.json.gz" % [date.year, date.month, date.day, date.hour])
end

#read_gha_file(file) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gh-archive.rb', line 22

def read_gha_file(file)
    if file.path.end_with?(".json")
        content = file.read
    elsif file.path.end_with?(".gz") || file.path.start_with?("/tmp/open-uri")
        content = read_gha_file_content(file)
    else
        raise "Invalid file extension for #{file.path}: expected `.json.gz` or `json`,"
    end
        
    result = []
    content.lines.each do |line|
        result << JSON.parse(line)
    end
    
    return result
end

#read_gha_file_content(gz) ⇒ Object



15
16
17
18
19
20
# File 'lib/gh-archive.rb', line 15

def read_gha_file_content(gz)
    gzip = Zlib::GzipReader.new(gz)
    return gzip.read
ensure
    gzip.close if gzip
end