Module: RailFeeds::NetworkRail::CORPUS
- Defined in:
- lib/rail_feeds/network_rail/corpus.rb
Overview
A module for getting information out of the CORPUS data.
Defined Under Namespace
Classes: Data
Class Method Summary collapse
-
.download(file, credentials = Credentials) ⇒ Object
Download the current CORPUS data.
-
.fetch(credentials = Credentials) ⇒ IO
Fetch the current CORPUS data.
-
.fetch_data(credentials = Credentials) ⇒ Array<RailFeeds::NetworkRail::CORPUS::Data>
Load CORPUS data from the internet.
-
.load_file(file) ⇒ Array<RailFeeds::NetworkRail::CORPUS::Data>
Load CORPUS data from either a .json or .json.gz file.
Class Method Details
.download(file, credentials = Credentials) ⇒ Object
Download the current CORPUS data.
15 16 17 18 |
# File 'lib/rail_feeds/network_rail/corpus.rb', line 15 def self.download(file, credentials = Credentials) client = HTTPClient.new(credentials: credentials) client.download 'ntrod/SupportingFileAuthenticate?type=CORPUS', file end |
.fetch(credentials = Credentials) ⇒ IO
Fetch the current CORPUS data.
23 24 25 26 |
# File 'lib/rail_feeds/network_rail/corpus.rb', line 23 def self.fetch(credentials = Credentials) client = HTTPClient.new(credentials: credentials) client.fetch 'ntrod/SupportingFileAuthenticate?type=CORPUS' end |
.fetch_data(credentials = Credentials) ⇒ Array<RailFeeds::NetworkRail::CORPUS::Data>
Load CORPUS data from the internet.
43 44 45 46 47 48 |
# File 'lib/rail_feeds/network_rail/corpus.rb', line 43 def self.fetch_data(credentials = Credentials) client = HTTPClient.new(credentials: credentials) client.fetch_unzipped('ntrod/SupportingFileAuthenticate?type=CORPUS') do |file| break parse_json file.read end end |
.load_file(file) ⇒ Array<RailFeeds::NetworkRail::CORPUS::Data>
Load CORPUS data from either a .json or .json.gz file.
31 32 33 34 35 36 37 |
# File 'lib/rail_feeds/network_rail/corpus.rb', line 31 def self.load_file(file) Zlib::GzipReader.open(file) do |gz| parse_json gz.read end rescue Zlib::GzipFile::Error parse_json File.read(file) end |