Class: ActiveTriple

Inherits:
Object
  • Object
show all
Defined in:
lib/active_triple.rb,
lib/active_triple/search.rb,
lib/active_triple/connectors/post_to_url_connector.rb,
lib/active_triple/connectors/triple_store_connector.rb

Defined Under Namespace

Modules: Connectors, Search

Constant Summary collapse

@@connector =
Connectors::PostToUrlConnector

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActiveTriple

Returns a new instance of ActiveTriple.



7
8
9
# File 'lib/active_triple.rb', line 7

def initialize
  
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/active_triple.rb', line 13

def method_missing(m, *args, &block)
  if Search.respond_to?(m)
    statements = Search.send(m, *args)
    add_triple(statements) 
  elsif Array.new.respond_to?(m)
    get_data.send(m, *args, &block)
  else  
    super
  end
end

Class Method Details

.binding_idObject



53
54
55
# File 'lib/active_triple.rb', line 53

def self.binding_id
  "output"
end

.binding_variableObject



57
58
59
# File 'lib/active_triple.rb', line 57

def self.binding_variable
  "?#{binding_id}"
end

.connectorObject



37
38
39
# File 'lib/active_triple.rb', line 37

def self.connector
  @@connector
end

.method_missing(m, *args) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/active_triple.rb', line 24

def self.method_missing(m, *args)
  if Search.respond_to?(m) || m.to_sym == :limit
    active_triple = new
    active_triple.send(m, *args)
  else
    super
  end
end

.set_connector(connector) ⇒ Object



33
34
35
# File 'lib/active_triple.rb', line 33

def self.set_connector(connector)
  @@connector = connector
end

Instance Method Details

#add_triple(statement) ⇒ Object



42
43
44
45
46
47
# File 'lib/active_triple.rb', line 42

def add_triple(statement)
  @triples ||= Array.new
  @triples << statement
  @triples.flatten!
  return self
end

#allObject



70
71
72
# File 'lib/active_triple.rb', line 70

def all
  get_data
end

#get_dataObject



74
75
76
77
78
79
80
81
# File 'lib/active_triple.rb', line 74

def get_data
  connection = self.class.connector.send_data(
    :binding => self.class.binding_id,
    :limit => number_of_items,
    :triples => triples           
  )  
  connection.response
end

#limit(number_of_items) ⇒ Object



61
62
63
64
# File 'lib/active_triple.rb', line 61

def limit(number_of_items)
  @number_of_items = number_of_items
  return self
end

#number_of_itemsObject



66
67
68
# File 'lib/active_triple.rb', line 66

def number_of_items
  @number_of_items || '10'
end

#triplesObject



49
50
51
# File 'lib/active_triple.rb', line 49

def triples
  TripleParser.to_rdf(@triples).join("\n")
end