bel_parser 1.0.0.alpha.30-java → 1.0.0.alpha.31-java

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: 7a3d560aba5aa2f79f840d9b53b44c381e94ee7d
4
- data.tar.gz: 4cddb86997108e3991136e2a86543e7fbbed2579
3
+ metadata.gz: fa04261c4ab5fb7567aa559b39547ce55587533b
4
+ data.tar.gz: 40cb25e2563b4e0e58c1ab45859c176a4dd7ac2e
5
5
  SHA512:
6
- metadata.gz: adba0d6d5c1a2e779daf6d2b2b167f7990d43e31d0eb193afdad61c36ff4ba007082d5bef1f4981b723b3135266284fe0913b08e22649c3a2387660e1e902305
7
- data.tar.gz: 95c9121edaf26dffbb44929c1d4ff2b85849143ee070ed3df1cbebd3c06f1a77b8eeedee6248f22ed0f66ca01c7e148b73978cd65fc770dcf07bb5b7e65cdbae
6
+ metadata.gz: 761629499e9952307150811a2f6a3339913c6341f0fd74b52cabde34db19212f06d64ddf18d7e9cec6f55b42864804358699c142ed66373f2f649f1c7cb4df8a
7
+ data.tar.gz: f445020c91a30361c321b8ae470642e77572dfab288b2cfe5697fbb5b1c7fa2ede02dff7cedf4aaf49656a7ad35818b18ca2e195856438b482cb3dc704e70fd2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.30
1
+ 1.0.0.alpha.31
@@ -8,7 +8,7 @@ module BELParser
8
8
  include BELParser::Quoting
9
9
  include Comparable
10
10
 
11
- attr_accessor :namespace, :value
11
+ attr_reader :namespace, :value
12
12
 
13
13
  def initialize(namespace, value)
14
14
  raise(ArgumentError, 'value is nil') unless value
@@ -21,6 +21,22 @@ module BELParser
21
21
  @value = value
22
22
  end
23
23
 
24
+ def namespace=(namespace)
25
+ unless namespace.nil? || namespace.is_a?(Namespace)
26
+ raise(
27
+ ArgumentError,
28
+ "namespace: expected nil or Namespace, actual #{namespace.class}")
29
+ end
30
+
31
+ @namespace = namespace
32
+ end
33
+
34
+ def value=(value)
35
+ raise(ArgumentError, 'value is nil') unless value
36
+
37
+ @value = value
38
+ end
39
+
24
40
  def encoding
25
41
  nsv = @namespace[@value]
26
42
  return nil unless nsv
@@ -72,7 +88,7 @@ module BELParser
72
88
  namespace =
73
89
  if prefix.identifier
74
90
  keyword = prefix.identifier.string_literal
75
- namespace_hash[keyword]
91
+ Namespace.new(keyword, namespace_hash[keyword])
76
92
  else
77
93
  nil
78
94
  end
@@ -44,7 +44,6 @@ module BELParser
44
44
  @comment = comment
45
45
 
46
46
  if @relationship && !@object
47
- require 'pry'; binding.pry
48
47
  raise(
49
48
  ArgumentError,
50
49
  "object must be set when specifying a relationship")
@@ -6,19 +6,36 @@ module BELParser
6
6
  class Term
7
7
  include Comparable
8
8
 
9
- attr_accessor :function, :arguments
9
+ attr_reader :function, :arguments
10
10
 
11
11
  def initialize(function, *arguments)
12
+ self.function = function
13
+ self.arguments = arguments
14
+ end
15
+
16
+ def function=(function)
12
17
  unless function && function.is_a?(BELParser::Language::Function)
13
18
  raise(
14
19
  ArgumentError,
15
20
  %(function: expected Function, actual #{function.class}))
16
21
  end
17
22
  @function = function
18
- @arguments = (arguments ||= []).flatten
19
23
  end
20
24
 
21
- def <<(item)
25
+ def arguments=(*args)
26
+ args = (args ||= []).flatten
27
+ invalid = args.any?(&method(:invalid_argument?))
28
+ raise(
29
+ ArgumentError,
30
+ 'args must be Parameter or Term objects') if invalid
31
+
32
+ @arguments = args
33
+ end
34
+
35
+ def <<(arg)
36
+ raise(
37
+ ArgumentError,
38
+ 'argument must be Parameter or Term') if invalid_argument?(arg)
22
39
  @arguments << item
23
40
  end
24
41
 
@@ -47,6 +64,13 @@ module BELParser
47
64
  nil
48
65
  end
49
66
  end
67
+
68
+ private
69
+
70
+ def invalid_argument?(arg)
71
+ !arg.is_a?(BELParser::Expression::Model::Parameter) &&
72
+ !arg.is_a?(BELParser::Expression::Model::Term)
73
+ end
50
74
  end
51
75
 
52
76
  module Converters
@@ -90,4 +114,3 @@ module BELParser
90
114
  end
91
115
  end
92
116
  end
93
-
@@ -65,10 +65,12 @@ module BELParser
65
65
  def parse
66
66
  case @input
67
67
  when ::String # conflicts with ...AST::String
68
+ results = parse_string(@input, @filter)
69
+ return nil if results.nil?
68
70
  convert_ast(
69
71
  @spec,
70
72
  @namespaces,
71
- parse_string(@input, @filter).first)
73
+ results.first)
72
74
  when Array
73
75
  convert_multiple(
74
76
  parse_array(@input, @filter),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bel_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.30
4
+ version: 1.0.0.alpha.31
5
5
  platform: java
6
6
  authors:
7
7
  - Anthony Bargnesi