truth_serum 0.4.2 → 0.4.3

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: 481325393cb070fe642976b798174028b1cab102
4
- data.tar.gz: 02e677d5647e0c5ba3975a568347ab973428f458
3
+ metadata.gz: 590e540a36b34b56954e0faf0fba315eb8042a6b
4
+ data.tar.gz: f833f7c7ac478dbf6c9734df218645bfc2d5dd1c
5
5
  SHA512:
6
- metadata.gz: aacdbaca8bcc71dea85002dd4322ea66c49a9aea893c94d1cd3bc028a999645e77322e4d4a1d9f1b6cc615020f9347107234913f39ac7a328e619c02f541bd22
7
- data.tar.gz: 39f70a2285576824d300aec02c6b8a317d6cfc7372c7c8e57d21a5179291d9dedde7ad5968c846174ed418ae3c6a126bda7f2bfde742faaf46781c0fd08a48e4
6
+ metadata.gz: 738641475d633e50d67471307cd8ecf1e871aa5219bd64e15ae0714872e50ea1ac279dce7e2414e18c917ea4d3e63ff865cd7dc610a57ee79dd42e6c1fdce4a6
7
+ data.tar.gz: f5ddc48b3fff0bd64cfd70f8ea10564aad0950967735eb18c19b07ae50fcc6a39537d46ede6186e15d1ef0629a6de55bb880a755676bbb74476c9db9c270e89a
@@ -82,6 +82,8 @@ module TruthSerum
82
82
  append("\r")
83
83
  when 'n'
84
84
  append("\n")
85
+ when nil
86
+ append('\\') # EOF, treat preceding \ as literal
85
87
  else # '\\' '"' and everything else is passed verbatim
86
88
  append(char)
87
89
  end
@@ -98,7 +100,8 @@ module TruthSerum
98
100
  end
99
101
 
100
102
  def emit(type)
101
- super(Token.new(type, @buffer || ''))
103
+ @buffer ||= ''
104
+ super(Token.new(type, @buffer))
102
105
  @buffer = nil
103
106
  end
104
107
  end
@@ -8,19 +8,15 @@ module TruthSerum
8
8
  # convert result stream to hash
9
9
  def execute
10
10
  @negate = false
11
- result = {
11
+ @hash = {
12
12
  terms: [],
13
13
  negative_terms: [],
14
14
  filters: {},
15
15
  negative_filters: {}
16
16
  }
17
17
 
18
- stream = super
19
- until stream.empty?
20
- result = merge_result(result, stream.shift)
21
- end
22
-
23
- result
18
+ super
19
+ @hash
24
20
  end
25
21
 
26
22
  state :start do
@@ -109,32 +105,22 @@ module TruthSerum
109
105
  type = @negate ? :negative_terms : :terms
110
106
  @negate = false
111
107
 
112
- emit(type => [term])
108
+ if @hash.key?(type)
109
+ @hash[type] << term
110
+ else
111
+ @hash[type] = [term]
112
+ end
113
113
  end
114
114
 
115
115
  def emit_filter(key, value)
116
116
  type = @negate ? :negative_filters : :filters
117
117
  @negate = false
118
118
 
119
- emit(type => { key => value })
120
- end
121
-
122
- # simplified 1-deep merge
123
- def merge_result(x, y)
124
- result = x.merge({})
125
- y.each do |key, value|
126
- if result.key?(key)
127
- if value.is_a?(Hash)
128
- result[key] = result[key].merge(value)
129
- elsif value.is_a?(Array)
130
- result[key] = result[key] + value
131
- end
132
- else
133
- result[key] = value
134
- end
119
+ if @hash.key?(type)
120
+ @hash[type][key] = value
121
+ else
122
+ @hash[type] = { key => value }
135
123
  end
136
-
137
- result
138
124
  end
139
125
  end
140
126
  end
@@ -11,6 +11,14 @@ module TruthSerum
11
11
 
12
12
  attr_accessor :type, :text
13
13
 
14
+ class << self
15
+ def from_array(arr)
16
+ arr.map do |type, text|
17
+ Token.new(type, text)
18
+ end
19
+ end
20
+ end
21
+
14
22
  def initialize(type, text)
15
23
  @type = type
16
24
  @text = text
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TruthSerum
3
- VERSION = '0.4.2'
3
+ VERSION = '0.4.3'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truth_serum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chakrit Wichian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler