Class: Amigo::Variables

Inherits:
Object show all
Includes:
Hamster::Immutable
Defined in:
lib/amigo/variables.rb

Defined Under Namespace

Modules: ALL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names) ⇒ Variables

Returns a new instance of Variables.



31
32
33
# File 'lib/amigo/variables.rb', line 31

def initialize(names)
  @names = Hamster.list(*names)
end

Class Method Details

.new(*names) ⇒ Object



26
27
28
29
# File 'lib/amigo/variables.rb', line 26

def self.new(*names)
  return ALL if names.include?(:*)
  super(names)
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/amigo/variables.rb', line 47

def eql?(other)
  return true if other.equal?(self)
  other.class.equal?(self.class) &&
    @names.eql?(other.instance_variable_get(:@names))
end

#hashObject



54
55
56
# File 'lib/amigo/variables.rb', line 54

def hash
  @names.hash
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/amigo/variables.rb', line 35

def include?(name)
  @names.include?(name)
end

#map(row) ⇒ Object



39
40
41
# File 'lib/amigo/variables.rb', line 39

def map(row)
  @names.map { |name| row[name] }
end

#to_sparqlObject



43
44
45
# File 'lib/amigo/variables.rb', line 43

def to_sparql
  @names.map { |name| "?#{name}" }.join(" ")
end