Module: GHAUtils
- Included in:
- GHADownloader, GHAProvider
- Defined in:
- lib/gh-archive.rb
Instance Method Summary collapse
- #each_time(from, to) ⇒ Object
- #get_gha_filename(date) ⇒ Object
- #read_gha_file(file) ⇒ Object
- #read_gha_file_content(gz) ⇒ Object
Instance Method Details
#each_time(from, to) ⇒ Object
107 108 109 110 111 112 113 |
# 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) ⇒ Object
78 79 80 |
# 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) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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) ⇒ Object
82 83 84 85 86 87 |
# 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 |