Class: Avdata

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path('APT.txt', self.directory))
      self.apt_file = File.expand_path('APT.txt', self.directory)
    end
  end
  
end

Instance Attribute Details

#apt_fileObject

Returns the value of attribute apt_file.



7
8
9
# File 'lib/avdata.rb', line 7

def apt_file
  @apt_file
end

#directoryObject

Returns the value of attribute directory.



7
8
9
# File 'lib/avdata.rb', line 7

def directory
  @directory
end

Instance Method Details

#get_airportsObject



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