Class: Avdata
- Inherits:
-
Object
- Object
- Avdata
- Defined in:
- lib/avdata.rb
Instance Attribute Summary collapse
-
#apt_file ⇒ Object
Returns the value of attribute apt_file.
-
#directory ⇒ Object
Returns the value of attribute directory.
Instance Method Summary collapse
- #get_airports ⇒ Object
- #get_rows(file, prefix) ⇒ Object
-
#initialize(args) ⇒ Avdata
constructor
A new instance of Avdata.
Constructor Details
#initialize(args) ⇒ Avdata
Returns a new instance of Avdata.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/avdata.rb', line 9 def initialize args args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end if (self.directory != nil) && (File.directory?(self.directory)) if File.exists?(File.('APT.txt', self.directory)) self.apt_file = File.('APT.txt', self.directory) end end end |
Instance Attribute Details
#apt_file ⇒ Object
Returns the value of attribute apt_file.
7 8 9 |
# File 'lib/avdata.rb', line 7 def apt_file @apt_file end |
#directory ⇒ Object
Returns the value of attribute directory.
7 8 9 |
# File 'lib/avdata.rb', line 7 def directory @directory end |
Instance Method Details
#get_airports ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/avdata.rb', line 22 def get_airports if self.apt_file return get_rows(self.apt_file,'APT') else return [] end end |
#get_rows(file, prefix) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/avdata.rb', line 32 def get_rows(file,prefix) results = [] f = File.new(file, "r") while line = f.gets ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') valid_line = ic.iconv(line + ' ')[0..-2] if valid_line.match(/^#{prefix}/) results << Airport_record.new(valid_line) end end return results end |