Class: MajortomConnector::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/majortom_connector/connector.rb

Instance Method Summary collapse

Constructor Details

#initialize(id_or_base_iri) ⇒ Connector

Returns a new instance of Connector.



4
5
6
7
# File 'lib/majortom_connector/connector.rb', line 4

def initialize(id_or_base_iri)
  return unless ready?
  config.map_id = id_or_base_iri.match(/^http/) ? find_topic_map_id_by_base_iri(id_or_base_iri) : id_or_base_iri
end

Instance Method Details

#clear_cacheObject



45
46
47
# File 'lib/majortom_connector/connector.rb', line 45

def clear_cache
  request.run('clearcache') if ready?
end

#configObject



61
62
63
# File 'lib/majortom_connector/connector.rb', line 61

def config
  @config ||= Config.new
end

#established?Boolean

Returns:

  • (Boolean)


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

def established?
  ready? && request.run('connectiontest').code == "0"
end

#find_topic_map_id_by_base_iri(base_iri) ⇒ Object



17
18
19
# File 'lib/majortom_connector/connector.rb', line 17

def find_topic_map_id_by_base_iri(base_iri)
  request.run('resolvetm', base_iri).data if ready?
end

#list_mapsObject



13
14
15
# File 'lib/majortom_connector/connector.rb', line 13

def list_maps
  request.run('topicmaps') if ready?
end

#ready?Boolean

Returns:

  • (Boolean)


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

def ready?
  config.ready?
end

#requestObject



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

def request
  @request ||= Request.new(config)
end

#search(query = "") ⇒ Object



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

def search(query = "")
  request.run('beru', query) if ready?
end

#sparql(query) ⇒ Object



29
30
31
# File 'lib/majortom_connector/connector.rb', line 29

def sparql(query)
  request.run('sparql', query) if ready?
end

#tmql(query) ⇒ Object



25
26
27
# File 'lib/majortom_connector/connector.rb', line 25

def tmql(query)
  request.run('tmql', query) if ready?
end

#to_ctmObject



41
42
43
# File 'lib/majortom_connector/connector.rb', line 41

def to_ctm
  request.run('ctm') if ready?
end

#to_xtmObject



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

def to_xtm
  request.run('xtm') if ready?
end

#topic_map_idObject



9
10
11
# File 'lib/majortom_connector/connector.rb', line 9

def topic_map_id
  config.map_id ||= ""
end

#topicsObject



21
22
23
# File 'lib/majortom_connector/connector.rb', line 21

def topics
  request.run('topics') if ready?
end