britebox 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b984224096de7c93471e4b5c00df2f83685ceb7
4
- data.tar.gz: 6f8825ccc06078bd2d86a0e284b4086343c2bd27
3
+ metadata.gz: 4b54286d6165fb16b7e7c0e920bb750b9de039c6
4
+ data.tar.gz: 43bfdc620b9a7d81dff3f87576ae02a3a7ca7745
5
5
  SHA512:
6
- metadata.gz: 7bcb3672dc53043bb600b140d8193ac065124a3c6f4cda7ee33d396015cc6ed60754543c1299b7c7cefa1787eba96a843004fd52cf9a7b743f5d5184ba314108
7
- data.tar.gz: 9fcc5126c0c8728402f4dcbec8d14bb749febf1082728d099af763a0c18d6197c9fea5803ae1b42438db4a7a93e353eccd7b7d739da452b08c10fd2fff4e6a7a
6
+ metadata.gz: 0fcdb8abec1665bb6a984307dd75a150862949ff20f38fd6cebbc33d7dd627b4c1e23441056820a46fe155d4f134a7a99c0a83a4157cf2aee4b61aaf4de2455c
7
+ data.tar.gz: 7b4d2bfb68404e0a260a91250d11d46fa966002b4baa83812c07e9c6879e37eb0203162f388d12fb76841b7424609098deba73b2cd53a9b82546ef288a5385e6
@@ -1,7 +1,12 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+
1
4
  module Britebox
2
5
  class ExportBuffer
3
6
  def initialize(out_file_name, header_line, col_separator)
4
- @file = File.new out_file_name, 'w+'
7
+ @out_file_name = out_file_name
8
+
9
+ @file = Tempfile.new(File.basename(out_file_name))
5
10
  @col_separator = col_separator
6
11
  write_header_row(header_line)
7
12
  @last_exported_line_idx = 0
@@ -52,6 +57,7 @@ module Britebox
52
57
 
53
58
  def close
54
59
  @file.close
60
+ FileUtils.mv(@file.path, @out_file_name)
55
61
  end
56
62
 
57
63
  def status
@@ -10,7 +10,7 @@ module Britebox
10
10
 
11
11
  def initialize(file_name)
12
12
  @file_name = file_name
13
- @opts = {col_separator: nil, header_row: nil, email_index: nil}
13
+ @opts = {col_separator: nil, header_row: nil, email_index: nil, update_mode: nil}
14
14
  end
15
15
 
16
16
  def recognize!
@@ -121,7 +121,13 @@ module Britebox
121
121
  end
122
122
  end
123
123
  end
124
- @opts[:header_row] = hr + PLUS_HEADERS
124
+
125
+ if hr[-PLUS_HEADERS.size..-1] == PLUS_HEADERS
126
+ @opts[:update_mode] = true
127
+ @opts[:header_row] = hr
128
+ else
129
+ @opts[:header_row] = hr + PLUS_HEADERS
130
+ end
125
131
  end
126
132
 
127
133
  def is_separator?(sep, lines)
@@ -27,8 +27,18 @@ module Britebox
27
27
  item = Timeout.timeout(1) { in_buffer.pop } rescue nil
28
28
  break if item.nil?
29
29
 
30
+ contact_status = nil
31
+ line = item[:line]
30
32
  email = item[:line][opts[:email_index]]
31
- if email.to_s.match(FormatRecognizer::EMAIL_PATTERN)
33
+ if opts[:update_mode]
34
+ contact_status = item[:line][-FormatRecognizer::PLUS_HEADERS.size .. -1]
35
+ line = item[:line][0 .. -(FormatRecognizer::PLUS_HEADERS.size + 1)]
36
+ end
37
+
38
+ if contact_status && ['valid', 'invalid'].include?(contact_status[0])
39
+ # do nothing, contact already verified
40
+
41
+ elsif email.to_s.match(FormatRecognizer::EMAIL_PATTERN)
32
42
  if Britebox::Config.simulate
33
43
  # Do not send real requests in this mode
34
44
  sleep(1)
@@ -42,12 +52,13 @@ module Britebox
42
52
  contact_status = ['error', false, false]
43
53
  end
44
54
  end
55
+
45
56
  else
46
57
  contact_status = ['invalid', false, false]
47
58
  end
48
59
 
49
60
  fj.semaphore.synchronize do
50
- out_buffer << {n: item[:n], line: item[:line] + contact_status}
61
+ out_buffer << {n: item[:n], line: line + contact_status}
51
62
  fj.size_processed += CSV.generate_line(item[:line], col_sep: opts[:col_separator]).size
52
63
  end
53
64
  end
@@ -1,3 +1,3 @@
1
1
  module Britebox
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: britebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shapiotko
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-22 00:00:00.000000000 Z
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: brite-api