Class: ULS::Database
- Inherits:
-
Object
- Object
- ULS::Database
- Defined in:
- lib/uls/database.rb
Overview
Used to interact with the FCC ‘database’ files. These files are compressed files containing several individual pipe-delimited data files.
Instance Attribute Summary collapse
-
#compressed_file ⇒ Object
Returns the value of attribute compressed_file.
Instance Method Summary collapse
- #clean ⇒ Object
- #delete ⇒ Object
- #delete! ⇒ Object
- #extract ⇒ Object
- #extracted? ⇒ Boolean
- #extracted_path ⇒ Object
- #form_primary ⇒ Object
- #form_secondary ⇒ Object
-
#initialize(filename) ⇒ Database
constructor
Use to construct an interface to the Database zipfile/directory retrieved from the FCC.
- #name_and_addresses ⇒ Object
Constructor Details
#initialize(filename) ⇒ Database
Use to construct an interface to the Database zipfile/directory retrieved from the FCC. The filename may either be a zip file, in which case it will be extracted to the temporary directory, or may be an already extract directory containing the various ‘database’ files.
14 15 16 17 18 19 20 21 |
# File 'lib/uls/database.rb', line 14 def initialize(filename) path = Pathname.new(filename) if path.directory? @extracted_path = filename else @compressed_file = filename end end |
Instance Attribute Details
#compressed_file ⇒ Object
Returns the value of attribute compressed_file.
7 8 9 |
# File 'lib/uls/database.rb', line 7 def compressed_file @compressed_file end |
Instance Method Details
#clean ⇒ Object
58 59 60 |
# File 'lib/uls/database.rb', line 58 def clean File.rmdir(extracted_path) end |
#delete ⇒ Object
62 63 64 |
# File 'lib/uls/database.rb', line 62 def delete File.delete(compressed_file) end |
#delete! ⇒ Object
66 67 68 69 70 |
# File 'lib/uls/database.rb', line 66 def delete! clean if extracted? delete end |
#extract ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/uls/database.rb', line 49 def extract FileUtils.mkdir_p(extracted_path) Zip::File.open(compressed_file) do |opened_file| opened_file.each do |entry| entry.extract("#{extracted_path}/#{entry.name}") end end end |
#extracted? ⇒ Boolean
45 46 47 |
# File 'lib/uls/database.rb', line 45 def extracted? Dir.exist?(extracted_path) end |
#extracted_path ⇒ Object
41 42 43 |
# File 'lib/uls/database.rb', line 41 def extracted_path @extracted_path ||= "#{ULS.configuration.tmpdir}/uls_#{Time.now.to_i}" end |
#form_primary ⇒ Object
29 30 31 32 33 |
# File 'lib/uls/database.rb', line 29 def form_primary extract unless extracted? DatFile.new("#{extracted_path}/HD.dat") end |