Class: Empyrean::TweetLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/empyrean/tweetloader.rb

Class Method Summary collapse

Class Method Details

.read_directory(directory) ⇒ Object

Returns a list of file names in a directory.



27
28
29
30
31
32
33
34
35
36
# File 'lib/empyrean/tweetloader.rb', line 27

def self.read_directory(directory)
  files = []
  entries = Dir.entries(directory)
  entries.each do |e|
    if e =~ /^\d{4}_\d{2}\.js$/
      files << File.expand_path(e, directory)
    end
  end
  files.sort
end

.read_file(file) ⇒ Object

Reads a tweet file



40
41
42
43
44
45
46
# File 'lib/empyrean/tweetloader.rb', line 40

def self.read_file(file)
  puts "reading file #{file}"
  fh = File.open(file)
  contents = fh.read
  contents.sub! /Grailbird\.data\.tweets_\d{4}_\d{2} =/, '' # get rid of the JS assignment
  json_tweets = JSON.parse(contents)
end