module GHAUtils
Public Instance Methods
each_time(from, to) { |current_time| ... }
click to toggle source
# File lib/gh-archive.rb, line 107 def each_time(from, to) current_time = from while current_time < to yield current_time current_time += 3600 end end
get_gha_filename(date)
click to toggle source
# File lib/gh-archive.rb, line 78 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)
click to toggle source
# File lib/gh-archive.rb, line 89 def read_gha_file(file) if !file.is_a?(StringIO) && file.path.end_with?(".json") content = file.read elsif file.is_a?(StringIO) || 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)
click to toggle source
# File lib/gh-archive.rb, line 82 def read_gha_file_content(gz) gzip = Zlib::GzipReader.new(gz) return gzip.read ensure gzip.close if gzip end