micdrop 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 8e567ed6bfc0a336d28ec7f7cee0d3bd987109b83d1ac634071a79d875002824
4
- data.tar.gz: 0bd90f322d2201b782b3cca29213ffd8ba4078f671ce3a04302e9404ec7a14f7
3
+ metadata.gz: 3434b290ec3a387c438161abc20e6c1bc4ef4e1681af6c66534e156bf282e021
4
+ data.tar.gz: ae5d8e26616664b73a0c2bfb2281744340bf79109873ba383539161dc0fa29be
5
5
  SHA512:
6
- metadata.gz: ee163fb3d7be2fd634e465196fd5053622d9b46246cf5177a75c00bbbdf7cba99c60d7fae661648c652e8a8f500580f3342b7f4fb99764330960c3fecbd62c86
7
- data.tar.gz: d081c87bcb894e3718290794892be8e48283507615cdeee2b6b47206fb3497f1e45f26d32894b58f7b0cc312031f75c9cd48aca540e3fd35d4d912117cfa75c9
6
+ metadata.gz: 9302e808f46fcf5a976f6428733b7404d5f6f880e8fddb8003a47968167d468df8773f7d314de582e82c3f495408ad0d7861555e7e3a0b61bb634041287c61aa
7
+ data.tar.gz: 00fd2711e7f45c78632d3a67cd118c509e1dc448912d574190e2cd0b94f5b1c2e75b597b94843f49a26241adaef13cdb85e78ee0ba79ffca06c210ebc6f1a0ad
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Micdrop
6
+ module Ext
7
+ ##
8
+ # A module for working with the JSON-Lines (ND-JSON) format
9
+ module JsonLines
10
+ ##
11
+ # Takes a file, such as a pipe to another process, and interpret the results as JSON-Lines (ND-JSON)
12
+ class JsonLinesSource
13
+ def initialize(file, close: true)
14
+ @file = file
15
+ @close = close
16
+ end
17
+
18
+ def self.from_command(*args, **kwargs)
19
+ self.class.new(IO.popen(*args, **kwargs), close: true)
20
+ end
21
+
22
+ def each
23
+ return enum_for unless block_given?
24
+
25
+ @file.each_line do |line|
26
+ yield JSON.parse line
27
+ end
28
+ end
29
+
30
+ def close
31
+ @file.close if @close
32
+ end
33
+ end
34
+
35
+ ##
36
+ # Output data in JSON-Lines (ND-JSON) format
37
+ class JsonLinesSink
38
+ def initialize(file, close: true)
39
+ @file = file
40
+ @close = close
41
+ end
42
+
43
+ def <<(item)
44
+ JSON.dump(item, @file)
45
+ @file << "\n"
46
+ end
47
+
48
+ def close
49
+ @file.close if @close
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -78,7 +78,7 @@ module Micdrop
78
78
  frag = ::Nokogiri::HTML.fragment ""
79
79
  frag.content = @value
80
80
  @value = frag.to_s
81
- @value = @value.sub "\n", "<br/>" if nl2br
81
+ @value = @value.gsub "\n", "<br/>" if nl2br
82
82
  self
83
83
  end
84
84
 
@@ -100,7 +100,7 @@ module Micdrop
100
100
  frag = ::Nokogiri::HTML5.fragment ""
101
101
  frag.content = @value
102
102
  @value = frag.to_s
103
- @value = @value.sub "\n", "<br/>" if nl2br
103
+ @value = @value.gsub "\n", "<br/>" if nl2br
104
104
  self
105
105
  end
106
106
 
@@ -128,7 +128,8 @@ module Micdrop
128
128
  @record_context.put_bury keys, @value
129
129
  end
130
130
 
131
- def_delegators :@record_context, :static, :index, :collect_format_string, :collect_list, :stop, :skip, :flush
131
+ def_delegators :@record_context, :static, :index, :collect_format_string, :collect_list, :collect_kv, :stop, :skip,
132
+ :flush
132
133
 
133
134
  ### Debug transformers ###
134
135
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Micdrop
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/micdrop.rb CHANGED
@@ -38,6 +38,8 @@ module Micdrop
38
38
  else
39
39
  # TODO: error
40
40
  end
41
+ from.close if from.respond_to? :close
42
+ to.close if to.respond_to? :close
41
43
  end
42
44
 
43
45
  ##
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micdrop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominick Johnson
@@ -46,6 +46,7 @@ files:
46
46
  - examples/xml_to_sql.rb
47
47
  - lib/micdrop.rb
48
48
  - lib/micdrop/errors.rb
49
+ - lib/micdrop/ext/json_lines.rb
49
50
  - lib/micdrop/ext/microfocus.rb
50
51
  - lib/micdrop/ext/nokogiri.rb
51
52
  - lib/micdrop/ext/sequel.rb