metar-parser 0.2.1 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/metar/raw.rb +45 -16
- data/lib/metar/version.rb +3 -3
- metadata +5 -5
data/Rakefile
CHANGED
data/lib/metar/raw.rb
CHANGED
@@ -5,26 +5,27 @@ module Metar
|
|
5
5
|
|
6
6
|
class Raw
|
7
7
|
|
8
|
+
@@connection = nil
|
9
|
+
|
8
10
|
class << self
|
9
11
|
|
10
|
-
@connection = nil
|
11
12
|
|
12
13
|
def cache_connection
|
13
|
-
|
14
|
+
@@connection = connection
|
14
15
|
end
|
15
16
|
|
16
17
|
def connection
|
17
|
-
return
|
18
|
-
connection = Net::FTP.new('tgftp.nws.noaa.gov')
|
19
|
-
connection.login
|
20
|
-
connection.chdir('data/observations/metar/stations')
|
21
|
-
connection.passive = true
|
22
|
-
connection
|
18
|
+
return @@connection if @@connection
|
19
|
+
@@connection = Net::FTP.new('tgftp.nws.noaa.gov')
|
20
|
+
@@connection.login
|
21
|
+
@@connection.chdir('data/observations/metar/stations')
|
22
|
+
@@connection.passive = true
|
23
|
+
@@connection
|
23
24
|
end
|
24
25
|
|
25
|
-
def fetch(cccc)
|
26
|
+
def fetch( cccc )
|
26
27
|
s = ''
|
27
|
-
connection.retrbinary("RETR #{ cccc }.TXT", 1024) do |chunk|
|
28
|
+
connection.retrbinary( "RETR #{ cccc }.TXT", 1024 ) do | chunk |
|
28
29
|
s << chunk
|
29
30
|
end
|
30
31
|
s
|
@@ -32,16 +33,44 @@ module Metar
|
|
32
33
|
|
33
34
|
end
|
34
35
|
|
35
|
-
attr_reader :cccc
|
36
|
-
alias :to_s :metar
|
36
|
+
attr_reader :cccc
|
37
37
|
|
38
38
|
# Station is a string containing the CCCC code, or
|
39
39
|
# an object with a 'cccc' method which returns the code
|
40
|
-
def initialize(station,
|
40
|
+
def initialize( station, data = nil )
|
41
41
|
@cccc = station.respond_to?(:cccc) ? station.cccc : station
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
parse data if data
|
43
|
+
end
|
44
|
+
|
45
|
+
def data
|
46
|
+
fetch
|
47
|
+
@data
|
48
|
+
end
|
49
|
+
# #raw is deprecated, use #data
|
50
|
+
alias :raw :data
|
51
|
+
|
52
|
+
def time
|
53
|
+
fetch
|
54
|
+
@time
|
55
|
+
end
|
56
|
+
|
57
|
+
def metar
|
58
|
+
fetch
|
59
|
+
@metar
|
60
|
+
end
|
61
|
+
alias :to_s :metar
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def fetch
|
66
|
+
return if @data
|
67
|
+
parse Raw.fetch( @cccc )
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse( data )
|
71
|
+
@data = data
|
72
|
+
time, @metar = @data.split( "\n" )
|
73
|
+
@time = Time.parse( time )
|
45
74
|
end
|
46
75
|
|
47
76
|
end
|
data/lib/metar/version.rb
CHANGED
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:
|
4
|
+
hash: 53
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 9
|
9
|
+
- 7
|
10
|
+
version: 0.9.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Yates
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|