noaaish 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/noaaish/extractor.rb +16 -9
- data/lib/noaaish/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6807e1bf053998c145c7f274f0f8fe553b9ddeaa
|
4
|
+
data.tar.gz: 57141cecd357c26ffad7460136b93e51811bda83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a504ea0cfd16e33bc21e86709481ec59f2c75d9d7f3cb557714591d08be9de0d94c5e15d6a9f14bc7d6ec50d344149133eb283645975df03317cd2e6cef04a
|
7
|
+
data.tar.gz: c2bbad6afdbab31eae2bcdf25ff0f371556a68143e2b0b178cee4e16ce50c9452079431fbb5e9912da73d9a956543413d5b6d52e051dc0df10d625e1f295ed8a
|
data/lib/noaaish/extractor.rb
CHANGED
@@ -3,22 +3,29 @@ require 'tempfile'
|
|
3
3
|
|
4
4
|
module Noaaish
|
5
5
|
class Extractor
|
6
|
-
def initialize(input, output=destination)
|
6
|
+
def initialize(input, output=destination, format=:hash)
|
7
7
|
@input = input
|
8
8
|
@destination = output
|
9
|
+
@format = format
|
9
10
|
end
|
10
11
|
|
11
|
-
attr_reader :input
|
12
|
+
attr_reader :input, :format
|
12
13
|
|
13
14
|
def call
|
14
15
|
# For each line, create a json record.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
hash = input.each_line.map { |line|
|
17
|
+
NOAA_FIELDS.inject({}) do |hash, (field, range)|
|
18
|
+
hash.merge(field => line[range])
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
case format
|
23
|
+
when :json
|
24
|
+
destination << hash.to_json
|
25
|
+
destination
|
26
|
+
when :hash
|
27
|
+
hash
|
28
|
+
end
|
22
29
|
end
|
23
30
|
|
24
31
|
def destination
|
data/lib/noaaish/version.rb
CHANGED