bel 0.4.0.beta.11 → 0.4.0.beta.12

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
  SHA1:
3
- metadata.gz: 548d6b84e170ccb7e8e575cea4008c7167ce0d33
4
- data.tar.gz: 3fb0d2f6b1097b95805a6f0012da005ac5b7fc60
3
+ metadata.gz: 1de2e3597f5e9e16484beb22668582c728a31296
4
+ data.tar.gz: f43c19636c538cf6efc1d69420e1d76183e0608c
5
5
  SHA512:
6
- metadata.gz: 19a1cd0adad981782608a06500ce8884f44c915fa5413b2940a88feb532dd183bd1a43a26a0604ff9022258a710160c66b6400524fa5c859f8774af0701389ce
7
- data.tar.gz: 1347303f1c419ae1942cfda04efc71f9eca778de6edb931e57eac8de9f42a66ab1298151b12cf86a28ba9e96a0c8c2219ee746e00392984b7d4a1c88e7a0886a
6
+ metadata.gz: 75d4efe4137aba17e5ab685282fa998b9e6013a3e7e67ba253651d51b0eb97a81d5ff82a7ef7fa5cd926a3cfd87787fdd0ec8c54d3a67b87789583e92798cb1f
7
+ data.tar.gz: 3d76283d55261eb0460b1828ba894fafeb344d48d8231d71252b1bcc5502b790e9415a125e00b8ee9b4fe8cfaf3cceb3a92a6aa57e0b055fa42a8af7f4e4e071
@@ -52,6 +52,9 @@ module BEL
52
52
  if args.length == 1
53
53
  enumerable = args.first
54
54
  if enumerable.respond_to? :each_pair
55
+ enumerable.keys.each do |key|
56
+ enumerable[key.to_s.to_sym] = enumerable.delete(key)
57
+ end
55
58
  (MEMBER_ORDER & enumerable.keys).each do |member|
56
59
  self.send(:"#{member}=", enumerable[member])
57
60
  end
@@ -10,7 +10,14 @@ module BEL
10
10
  include Enumerable
11
11
 
12
12
  def initialize(values = [])
13
- @values = values
13
+ @values = values.map { |item|
14
+ name = item[:name] || item['name']
15
+ value = item[:value] || item['value']
16
+ {
17
+ :name => name.to_sym,
18
+ :value => value
19
+ }
20
+ }
14
21
  end
15
22
 
16
23
  def_delegators :@values, :<<, :[], :"[]=",
@@ -15,7 +15,9 @@ module BEL
15
15
  if values.is_a? Array
16
16
  @values = Hash[
17
17
  values.map { |item|
18
- [item[:name].to_sym, item[:value]]
18
+ name = item[:name] || item['name']
19
+ value = item[:value] || item['value']
20
+ [name.to_sym, value]
19
21
  }
20
22
  ]
21
23
  else
@@ -82,7 +82,6 @@ module BEL::Translator::Plugins
82
82
  def namespaces(namespaces)
83
83
  return "" unless namespaces
84
84
 
85
- binding.pry
86
85
  namespaces.reduce("") { |bel, namespace|
87
86
  keyword = namespace[:keyword]
88
87
  uri = namespace[:uri]
@@ -14,10 +14,21 @@ module BEL::Translator::Plugins
14
14
  end
15
15
 
16
16
  def write(objects, writer = StringIO.new, options = {})
17
- BelYielder.new(objects).each { |bel_part|
18
- writer << "#{bel_part}"
19
- writer.flush
20
- }
17
+ if block_given?
18
+ BelYielder.new(objects).each { |bel_part|
19
+ yield bel_part
20
+ }
21
+ else
22
+ if writer
23
+ BelYielder.new(objects).each { |bel_part|
24
+ writer << "#{bel_part}"
25
+ writer.flush
26
+ }
27
+ writer
28
+ else
29
+ BelYielder.new(objects)
30
+ end
31
+ end
21
32
  end
22
33
  end
23
34
  end
@@ -18,26 +18,42 @@ module BEL::Translator::Plugins
18
18
  end
19
19
 
20
20
  def write(objects, writer = StringIO.new, options = {})
21
- write_array_start(writer)
22
- begin
23
- evidence_enum = objects.each
21
+ json_strings = Enumerator.new { |yielder|
22
+ yielder << '['
23
+ begin
24
+ evidence_enum = objects.each
24
25
 
25
- # write first evidence object
26
- evidence = evidence_enum.next
27
- ::BEL::JSON.write(wrap(evidence), writer)
28
-
29
- # each successive evidence starts with a comma
30
- while true
26
+ # write first evidence object
31
27
  evidence = evidence_enum.next
32
- writer << ","
33
- ::BEL::JSON.write(wrap(evidence), writer)
28
+ yielder << ::BEL::JSON.write(wrap(evidence), nil)
29
+
30
+ # each successive evidence starts with a comma
31
+ while true
32
+ evidence = evidence_enum.next
33
+ yielder << ','
34
+ yielder << ::BEL::JSON.write(wrap(evidence), nil)
35
+ end
36
+ rescue StopIteration
37
+ # end of evidence hashes
34
38
  end
35
- rescue StopIteration
36
- # end of evidence hashes
37
- end
38
- write_array_end(writer)
39
+ yielder << ']'
40
+ }
39
41
 
40
- writer
42
+ if block_given?
43
+ json_strings.each do |string|
44
+ yield string
45
+ end
46
+ else
47
+ if writer
48
+ json_strings.each do |string|
49
+ writer << string
50
+ writer.flush
51
+ end
52
+ writer
53
+ else
54
+ json_strings
55
+ end
56
+ end
41
57
  end
42
58
 
43
59
  private
@@ -24,6 +24,7 @@ module BEL::Translator::Plugins
24
24
  writer << xml_data
25
25
  writer.flush
26
26
  }
27
+ writer
27
28
  else
28
29
  XBELYielder.new(objects)
29
30
  end
@@ -77,12 +77,21 @@ module BEL::Translator::Plugins
77
77
  end
78
78
 
79
79
  def self.statement(statement, el_statement)
80
+ if statement.is_a?(String)
81
+ statement = BEL::Script.parse(statement.to_s).find { |x|
82
+ x.is_a? BEL::Model::Statement
83
+ }
84
+ return el_statement if statement == nil
85
+ end
86
+
80
87
  if statement.relationship
81
88
  el_statement.add_attribute 'bel:relationship', statement.relationship
82
89
  end
83
90
 
84
- el_subject = self.subject(statement.subject)
85
- el_statement.add_element(el_subject)
91
+ if statement.subject
92
+ el_subject = self.subject(statement.subject)
93
+ el_statement.add_element(el_subject)
94
+ end
86
95
 
87
96
  if statement.object
88
97
  el_object = self.object(statement.object)
data/lib/bel/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BEL
2
- VERSION = '0.4.0.beta.11'
2
+ VERSION = '0.4.0.beta.12'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.beta.11
4
+ version: 0.4.0.beta.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Bargnesi