Class: CertOpenDataVisualizer::Visualize
- Inherits:
-
Object
- Object
- CertOpenDataVisualizer::Visualize
- Defined in:
- lib/cert_open_data_visualizer/visualize.rb
Constant Summary collapse
- CSV_DATA_URL =
"http://pilvilinna.cert.fi/opendata/autoreporter/csv.zip"
Instance Attribute Summary collapse
-
#all_data ⇒ Object
Returns the value of attribute all_data.
-
#cacher ⇒ Object
Returns the value of attribute cacher.
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize ⇒ Visualize
constructor
A new instance of Visualize.
- #maybe_download ⇒ Object
- #maybe_extract_and_list_files ⇒ Object
- #maybe_read_and_merge_files(files) ⇒ Object
- #parse ⇒ Object
- #write_tmp_file(filename, contents) ⇒ Object
Constructor Details
#initialize ⇒ Visualize
Returns a new instance of Visualize.
12 13 14 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 12 def initialize @cacher = DummyCacher.new end |
Instance Attribute Details
#all_data ⇒ Object
Returns the value of attribute all_data.
9 10 11 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 9 def all_data @all_data end |
#cacher ⇒ Object
Returns the value of attribute cacher.
9 10 11 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 9 def cacher @cacher end |
Instance Method Details
#download ⇒ Object
31 32 33 34 35 36 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 31 def download puts "Downloading, may take a while depending on your connection" data = HTTParty.get(CSV_DATA_URL).body puts "Done" write_tmp_file("cert.zip", data) end |
#maybe_download ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 23 def maybe_download if @cacher.file_exists?("cert.zip") puts "File found in cache, not downloading" else download end end |
#maybe_extract_and_list_files ⇒ Object
42 43 44 45 46 47 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 42 def maybe_extract_and_list_files if @cacher.file_exists? "cert.zip" and not @cacher.file_exists? "certfi_autoreporter_opendata_2006.csv" @cacher.unzip_file("cert.zip") end @cacher.find_files_matching("*.csv") end |
#maybe_read_and_merge_files(files) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 49 def maybe_read_and_merge_files(files) if @cacher.file_exists? "all_data.json" @all_data = JSON.parse(File.read(@cacher.get_from_cache("all_data.json"))) else @all_data = get_csvs(files) write_tmp_file("all_data.json", @all_data.to_json) end @all_data end |
#parse ⇒ Object
16 17 18 19 20 21 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 16 def parse maybe_download files = maybe_extract_and_list_files maybe_read_and_merge_files(files) self end |
#write_tmp_file(filename, contents) ⇒ Object
38 39 40 |
# File 'lib/cert_open_data_visualizer/visualize.rb', line 38 def write_tmp_file(filename, contents) @cacher.write_file_to_cache filename, contents end |