Class: Ontopia::Topicmaps::Topicmap
- Inherits:
-
Object
- Object
- Ontopia::Topicmaps::Topicmap
- Defined in:
- lib/ontopia/topicmaps/topicmap.rb
Defined Under Namespace
Classes: RowMapper
Constant Summary collapse
- TOPICMAP_READER =
{ '.ctm' => :CTMTopicMapReader, '.jtm' => :JTMTopicMapReader, '.ltm' => :LTMTopicMapReader, '.rdf' => :RDFTopicMapReader, '.xfml' => :XFMLTopicMapReader, '.xtm' => :XTMTopicMapReader }
- QUERY =
{ all_topics: "select $TOPIC from\n topic($TOPIC),\n item-identifier($TOPIC, $_)?\n EOT\n count_all_topics: <<-EOT\nselect count($TOPIC) from\n topic($TOPIC),\n item-identifier($TOPIC, $_)?\n EOT\n}\n",
- QUERY_PROJECTION_RE =
%r{\bselect\s+(.+)\s+from\b}i
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#tm ⇒ Object
readonly
Returns the value of attribute tm.
Class Method Summary collapse
Instance Method Summary collapse
- #count(query = nil, declarations = nil) ⇒ Object
- #extract_query_projection(query) ⇒ Object
- #extract_query_variables(query) ⇒ Object
-
#initialize(file) ⇒ Topicmap
constructor
A new instance of Topicmap.
- #query(query = nil, declarations = nil, str = nil) ⇒ Object
- #query_maps(query = nil, declarations = nil) ⇒ Object
- #topics(value_str = nil, key_str = nil) ⇒ Object
Constructor Details
#initialize(file) ⇒ Topicmap
Returns a new instance of Topicmap.
65 66 67 68 69 70 71 72 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 65 def initialize(file) Topicmaps.setup_classpath @file = file.include?(File::SEPARATOR) ? file : File.join(Topicmaps.base, 'topicmaps', file) @tm = read(@file) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
74 75 76 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 74 def file @file end |
#tm ⇒ Object (readonly)
Returns the value of attribute tm.
74 75 76 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 74 def tm @tm end |
Class Method Details
.extract_query_projection(query) ⇒ Object
58 59 60 61 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 58 def extract_query_projection(query) projection = query[QUERY_PROJECTION_RE, 1] projection.delete('$,').split if projection end |
Instance Method Details
#count(query = nil, declarations = nil) ⇒ Object
76 77 78 79 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 76 def count(query = nil, declarations = nil) query ||= :count_all_topics query_for_list(query, declarations) { |i,| i }.first || 0 end |
#extract_query_projection(query) ⇒ Object
102 103 104 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 102 def extract_query_projection(query) self.class.extract_query_projection(query) end |
#extract_query_variables(query) ⇒ Object
106 107 108 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 106 def extract_query_variables(query) query_wrapper.get_query_processor.parse(query).get_selected_variables.to_a end |
#query(query = nil, declarations = nil, str = nil) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 81 def query(query = nil, declarations = nil, str = nil) str = Topicmaps.stringifier(str || :default) query_for_list(query, declarations, &block_given? ? lambda { |i, *| yield(i, str) } : lambda { |i, *| str[i] }).to_a end |
#query_maps(query = nil, declarations = nil) ⇒ Object
88 89 90 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 88 def query_maps(query = nil, declarations = nil) query_wrapper(declarations).query_for_maps(query_string(query)).to_a end |
#topics(value_str = nil, key_str = nil) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/ontopia/topicmaps/topicmap.rb', line 92 def topics(value_str = nil, key_str = nil) hash, key_str = {}, Topicmaps.stringifier(key_str || :id) query(:all_topics, nil, value_str) { |i, str| hash[key_str[i]] = str[i] } hash end |