osv 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f22d1d56b0eba1e23ca192db2c70e68689486e2f0032672285017e1f98a530d2
4
- data.tar.gz: 6288dce70b95faf312e8aa244ba56a60c3d59b85bdd16a4a951060df78b97e1e
3
+ metadata.gz: 9a6579b30fb8761382666c3fcfa434d9234c3ebf508cad7b3045b9f4ebc2f8b7
4
+ data.tar.gz: afb793b1df201e876e955ed75904c729aa353bdee3ae374085902efdd4601603
5
5
  SHA512:
6
- metadata.gz: 5399b43ecd3987c73daf09341d51a1ee8e5d060f1085e9a7aac9b823ab723ccbbc4084c5c0c9abbd36e7e17becfcfa1757af6af3666e01ef3992a27e35b5b983
7
- data.tar.gz: 2a6d98b645af40ab08a5a01a2bcf5b67ce9ebff18a993e602f6b00fa2f3f80d65c63605a7f5a715286ac20751db0607c515686e4439156a4039ae24f49e95e10
6
+ metadata.gz: 4318353ec8b32f026d3a3c8675a26b6a6545faba213bba28ada9b0ab7d978ea8d7dd6a8e202aaefb765040cc0d54990fd94f8263bbf4ecd6a4150ab9f48e7cc6
7
+ data.tar.gz: d0c590105f070773f82a2e00c0c069439c55055cfe958e7eb3bcf443a83fb1d3dd1f099b93f2835a30797024451666e42f18aeaa361432824d18f77cfaa4748f
@@ -80,7 +80,6 @@ impl<'a, T: RecordParser + Send + 'static> RecordReaderBuilder<'a, T> {
80
80
 
81
81
  pub fn build(self) -> Result<RecordReader<T>, Error> {
82
82
  let readable = self.get_reader()?;
83
-
84
83
  let mut reader = csv::ReaderBuilder::new()
85
84
  .has_headers(self.has_headers)
86
85
  .delimiter(self.delimiter)
@@ -88,14 +87,13 @@ impl<'a, T: RecordParser + Send + 'static> RecordReaderBuilder<'a, T> {
88
87
  .from_reader(readable);
89
88
 
90
89
  let headers = RecordReader::<T>::get_headers(self.ruby, &mut reader, self.has_headers)?;
91
- let headers_clone = headers.clone();
92
90
  let null_string = self.null_string;
93
91
 
94
92
  let (sender, receiver) = kanal::bounded(self.buffer);
95
93
  let handle = thread::spawn(move || {
96
94
  let mut record = csv::StringRecord::new();
97
95
  while let Ok(true) = reader.read_record(&mut record) {
98
- let row = T::parse(&headers_clone, &record, &null_string);
96
+ let row = T::parse(&headers, &record, &null_string);
99
97
  if sender.send(row).is_err() {
100
98
  break;
101
99
  }
@@ -2,42 +2,50 @@ use std::collections::HashMap;
2
2
 
3
3
  pub trait RecordParser {
4
4
  type Output;
5
-
6
- fn parse(headers: &[String], record: &csv::StringRecord, null_string: &str) -> Self::Output;
5
+ fn parse<'a>(
6
+ headers: &'a [String],
7
+ record: &csv::StringRecord,
8
+ null_string: &str,
9
+ ) -> Self::Output;
7
10
  }
8
11
 
9
12
  impl RecordParser for HashMap<String, Option<String>> {
10
13
  type Output = Self;
11
-
12
- fn parse(headers: &[String], record: &csv::StringRecord, null_string: &str) -> Self::Output {
13
- headers
14
- .iter()
15
- .zip(record.iter())
16
- .map(|(header, field)| {
17
- let value = if field == null_string {
14
+ fn parse<'a>(
15
+ headers: &'a [String],
16
+ record: &csv::StringRecord,
17
+ null_string: &str,
18
+ ) -> Self::Output {
19
+ let mut map = HashMap::with_capacity(headers.len());
20
+ for (header, field) in headers.iter().zip(record.iter()) {
21
+ map.insert(
22
+ header.clone(),
23
+ if field == null_string {
18
24
  None
19
25
  } else {
20
26
  Some(field.to_string())
21
- };
22
- (header.clone(), value)
23
- })
24
- .collect()
27
+ },
28
+ );
29
+ }
30
+ map
25
31
  }
26
32
  }
27
33
 
28
34
  impl RecordParser for Vec<Option<String>> {
29
35
  type Output = Self;
30
-
31
- fn parse(_headers: &[String], record: &csv::StringRecord, null_string: &str) -> Self::Output {
32
- record
33
- .iter()
34
- .map(|field| {
35
- if field == null_string {
36
- None
37
- } else {
38
- Some(field.to_string())
39
- }
40
- })
41
- .collect()
36
+ fn parse<'a>(
37
+ _headers: &'a [String],
38
+ record: &csv::StringRecord,
39
+ null_string: &str,
40
+ ) -> Self::Output {
41
+ let mut vec = Vec::with_capacity(record.len());
42
+ for field in record.iter() {
43
+ vec.push(if field == null_string {
44
+ None
45
+ } else {
46
+ Some(field.to_string())
47
+ });
48
+ }
49
+ vec
42
50
  }
43
51
  }
data/lib/osv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OSV
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Jaremko