bel_parser 1.0.0.alpha.30 → 1.0.0.alpha.31

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: 3167ea36acf763ecdd0b9756d9a1a5f1e31d3bd6
4
- data.tar.gz: d6ab2ac234c3971af5c19348f379b47f98df2c08
3
+ metadata.gz: b66c29b979f579e866724c32df259c7e67bee1f0
4
+ data.tar.gz: 46faa2d6ceaa709dc4e8a75992f6398e64b610dc
5
5
  SHA512:
6
- metadata.gz: 890d334871e4d755c8e203927620c1f2526f97339efbf8d8fc09ca3635818fdc88796efd7b3d054a6c1705fc1547fb8d8103bf931cb42dbefcc6a0719f62bf29
7
- data.tar.gz: 0f81693cf46829b1870886a62754cdc58a16c174e7a1a6b44f8df18100f0bd61127a78d99c1e4d1d0bcb8b62a1172de7888bdbbb599d27b2439230fb4e685dcb
6
+ metadata.gz: 44b895beb08a3087895296438d3c76f5507450b808868fff4fb325d1d83ad7b7c8a56b15f9bd4176ce4083b4baaaf337d7bca9903ccd122ba5b7fd56501f639d
7
+ data.tar.gz: 5a7981737684e2f3a0a451c8072d9f8bb532ef66311c057b6a2b07d23c56144ebe15956de8f9ca9b56e19898487e80766508b2c164d7a1e82f156187f7f0185f
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: ruby
6
6
  authors:
7
7
  - Anthony Bargnesi