metar-parser 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
- require File.join(File.dirname(__FILE__), 'metar', 'raw')
2
- require File.join(File.dirname(__FILE__), 'metar', 'station')
3
- require File.join(File.dirname(__FILE__), 'metar', 'parser')
4
- require File.join(File.dirname(__FILE__), 'metar', 'report')
5
- require File.join(File.dirname(__FILE__), 'metar', 'version')
1
+ require 'metar/raw'
2
+ require 'metar/station'
3
+ require 'metar/parser'
4
+ require 'metar/report'
5
+ require 'metar/version'
6
6
 
7
7
  module Metar
8
8
 
@@ -15,3 +15,4 @@ module Metar
15
15
  end
16
16
 
17
17
  end
18
+
@@ -92,12 +92,14 @@ module Metar
92
92
  parser
93
93
  end
94
94
 
95
- attr_reader :station_code, :observer, :time, :wind, :variable_wind, :visibility, :runway_visible_range,
95
+ attr_reader :raw, :metar, :time
96
+ attr_reader :station_code, :observer, :wind, :variable_wind, :visibility, :runway_visible_range,
96
97
  :present_weather, :sky_conditions, :vertical_visibility, :temperature, :dew_point, :sea_level_pressure, :remarks
97
98
 
98
99
  def initialize(raw)
99
- @metar = raw.metar.clone
100
- @time = raw.time.clone
100
+ @raw = raw
101
+ @metar = raw.metar.clone
102
+ @time = raw.time.clone
101
103
  analyze
102
104
  end
103
105
 
@@ -9,13 +9,16 @@ module Metar
9
9
 
10
10
  class << self
11
11
 
12
-
13
12
  def cache_connection
14
13
  @@connection = connection
15
14
  end
16
15
 
17
16
  def connection
18
17
  return @@connection if @@connection
18
+ connect
19
+ end
20
+
21
+ def connect
19
22
  @@connection = Net::FTP.new('tgftp.nws.noaa.gov')
20
23
  @@connection.login
21
24
  @@connection.chdir('data/observations/metar/stations')
@@ -24,11 +27,20 @@ module Metar
24
27
  end
25
28
 
26
29
  def fetch( cccc )
27
- s = ''
28
- connection.retrbinary( "RETR #{ cccc }.TXT", 1024 ) do | chunk |
29
- s << chunk
30
+ attempts = 0
31
+ while attempts < 2
32
+ begin
33
+ s = ''
34
+ connection.retrbinary( "RETR #{ cccc }.TXT", 1024 ) do | chunk |
35
+ s << chunk
36
+ end
37
+ return s
38
+ rescue Net::FTPTempError, EOFError => e
39
+ connect
40
+ attempts += 1
41
+ end
30
42
  end
31
- s
43
+ raise "Net::FTP.retrbinary failed #{attempts} times"
32
44
  end
33
45
 
34
46
  end
@@ -54,6 +66,11 @@ module Metar
54
66
  @time
55
67
  end
56
68
 
69
+ def raw_time
70
+ fetch
71
+ @raw_time
72
+ end
73
+
57
74
  def metar
58
75
  fetch
59
76
  @metar
@@ -68,9 +85,9 @@ module Metar
68
85
  end
69
86
 
70
87
  def parse( data )
71
- @data = data
72
- time, @metar = @data.split( "\n" )
73
- @time = Time.parse( time )
88
+ @data = data
89
+ @raw_time, @metar = @data.split( "\n" )
90
+ @time = Time.parse( @raw_time )
74
91
  end
75
92
 
76
93
  end
@@ -43,6 +43,8 @@ module Metar
43
43
  reset_options!
44
44
  end
45
45
 
46
+ attr_reader :parser, :station
47
+
46
48
  def initialize(parser)
47
49
  @parser = parser
48
50
  @station = Station.find_by_cccc(@parser.station_code)
@@ -3,7 +3,7 @@ module Metar
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 9
6
- TINY = 10
6
+ TINY = 11
7
7
 
8
8
  STRING = [ MAJOR, MINOR, TINY ].join( '.' )
9
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metar-parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 47
4
+ hash: 45
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 10
10
- version: 0.9.10
9
+ - 11
10
+ version: 0.9.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Yates