Class: RDF::Query::Variable
- Inherits:
-
Object
- Object
- RDF::Query::Variable
- Defined in:
- lib/lib/extensions/variable.rb
Instance Attribute Summary collapse
-
#modifier ⇒ Object
readonly
Returns the value of attribute modifier.
Instance Method Summary collapse
- #bind(value, modifier = "=", strict = true) ⇒ Object
-
#initialize(name = nil, value = nil) ⇒ Variable
constructor
A new instance of Variable.
- #literal? ⇒ Boolean
- #strict? ⇒ Boolean
- #to_s ⇒ Object
- #unbound? ⇒ Boolean
- #value ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(name = nil, value = nil) ⇒ Variable
Returns a new instance of Variable.
6 7 8 9 10 11 |
# File 'lib/lib/extensions/variable.rb', line 6 def initialize(name = nil, value = nil) name = 'v%s' % rand(100000) if name.nil? @name, @values = name.to_sym, [] @strict = true bind(value) unless value.nil? end |
Instance Attribute Details
#modifier ⇒ Object (readonly)
Returns the value of attribute modifier.
4 5 6 |
# File 'lib/lib/extensions/variable.rb', line 4 def modifier @modifier end |
Instance Method Details
#bind(value, modifier = "=", strict = true) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lib/extensions/variable.rb', line 29 def bind(value, modifier = "=", strict = true) value = if value.respond_to?(:object) value.object else value end @modifier = case modifier when :eq then "=" when :nq then "!=" when :lt then "<" when :lte then "<=" when :gt then ">" when :gte then ">=" else modifier end @strict = strict add(value, modifier) end |
#literal? ⇒ Boolean
17 18 19 |
# File 'lib/lib/extensions/variable.rb', line 17 def literal? value.class == String && values.length == 1 && modifier == "=" end |
#strict? ⇒ Boolean
50 51 52 |
# File 'lib/lib/extensions/variable.rb', line 50 def strict? @strict end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/lib/extensions/variable.rb', line 54 def to_s unbound? ? "?#{name}" : "#{name}#{modifier}#{value}" end |
#unbound? ⇒ Boolean
13 14 15 |
# File 'lib/lib/extensions/variable.rb', line 13 def unbound? @values.empty? end |
#value ⇒ Object
21 22 23 |
# File 'lib/lib/extensions/variable.rb', line 21 def value @values.first.nil? ? nil : @values.first.last end |
#values ⇒ Object
25 26 27 |
# File 'lib/lib/extensions/variable.rb', line 25 def values @values.dup end |