class Ontopia::TLDR

Constants

VERSION

Private Instance Methods

doc_to_s(id, doc) click to toggle source
# File lib/ontopia/tldr.rb, line 300
def doc_to_s(id, doc)
  a, t, u, y = doc.values_at(*settings.document_keys)

  a = a.join('; ') if a.is_a?(Array)
  s = [a, t].compact.join(': ')

  if s.empty?
    s = "##{id}"
  elsif u
    s << " – #{u}"
  end

  s << " (#{y})" if y

  h(s)
end
get_documents(topics = @topics) click to toggle source
# File lib/ontopia/tldr.rb, line 269
def get_documents(topics = @topics)
  settings.topic_index.values_at(*topics).compact.inject(&:merge)
end
get_topic_maps(name, topic = @topic, hash = nil, str = nil) click to toggle source
# File lib/ontopia/tldr.rb, line 252
def get_topic_maps(name, topic = @topic, hash = nil, str = nil)
  hash ||= instance_variable_get("@#{name}")
  str  ||= Ontopia::Topicmaps.id_stringifier

  query = settings.tolog_maps[name] % topic
  keys  = settings.otm.extract_query_projection(query)

  settings.otm.query_maps(query).each { |map|
    values = map.values_at(*keys).map!(&str)
    topic, key = values.pop, values.pop

    (values.inject(hash) { |h, k| h[k] ||= {} }[key] ||= []) << topic
  }
rescue => err
  @error = err.to_s
end
get_topics(query = @query, param = @param, rules = @rules) click to toggle source
# File lib/ontopia/tldr.rb, line 245
def get_topics(query = @query, param = @param, rules = @rules)
  settings.otm.query(settings.tolog % [rules, "$#{param}", query])
rescue => err
  @error = err.to_s
  []
end
render_documents(documents = @documents) click to toggle source
# File lib/ontopia/tldr.rb, line 281
def render_documents(documents = @documents)
  ul_(documents.sort_by { |k,| k }, id: :documents) { |id, doc|
    [link_to_document(id, doc),
      'data-index' => doc_to_s(id, doc).downcase]
  }
end
render_topics(topics = @topics) click to toggle source
# File lib/ontopia/tldr.rb, line 273
def render_topics(topics = @topics)
  ul_(topics.sort, id: :topics) { |topic|
    [link_to_topic(topic),
      ' (', settings.topic_index[topic].size, ')',
      'data-index' => topic_to_s(topic).downcase]
  }
end
render_topics_hash(hash) click to toggle source
# File lib/ontopia/tldr.rb, line 288
def render_topics_hash(hash)
  ul_(hash.map { |k, v| [topic_to_s(k), k, v] }.sort) { |name, key, value|
    [link_to_topic(key, name),
      value.is_a?(Hash) ? render_topics_hash(value) :
        ul_(value.sort.uniq) { |topic| link_to_topic(topic) }]
  }
end
to_render_hash() click to toggle source
Calls superclass method
# File lib/ontopia/tldr.rb, line 230
def to_render_hash
  super(
    d: @document || @documents,
    e: @error,
    i: @id,
    l: @relations,
    o: @roles,
    p: @param,
    q: @query,
    r: @rules,
    t: @topic || @topics,
    y: @types
  )
end
topic_to_s(topic) click to toggle source
# File lib/ontopia/tldr.rb, line 296
def topic_to_s(topic)
  h(settings.topics[topic] || topic.tr('_', ' '))
end