Class: Note::Base
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Note::Base
- Defined in:
- app/models/note/base.rb
Overview
Copyright 2011-2013 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Direct Known Subclasses
Class Method Summary collapse
-
.by_language(lang_code) ⇒ Object
********** Scopes.
- .by_owner(owner) ⇒ Object
- .by_owner_type(klass) ⇒ Object
- .by_query_value(query) ⇒ Object
- .edit_partial_name(obj) ⇒ Object
- .for_concepts ⇒ Object
- .for_labels ⇒ Object
- .partial_name(obj) ⇒ Object
- .search_result_partial_name ⇒ Object
- .single_query(params = {}) ⇒ Object
- .view_section(obj) ⇒ Object
- .view_section_sort_key(obj) ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
********** Methods.
- #build_search_result_rdf(document, result) ⇒ Object
-
#from_annotation_list!(str) ⇒ Object
TODO: This should move to umt because the “list” is more or less proprietary.
- #to_s ⇒ Object
Class Method Details
.by_language(lang_code) ⇒ Object
********** Scopes
47 48 49 50 51 52 53 54 55 |
# File 'app/models/note/base.rb', line 47 def self.by_language(lang_code) lang_code = Array.wrap(lang_code).flatten.compact if lang_code.none? || lang_code.include?(nil) where(arel_table[:language].eq(nil).or(arel_table[:language].in(lang_code))) else where(language: lang_code) end end |
.by_owner(owner) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'app/models/note/base.rb', line 73 def self.by_owner(owner) if owner.is_a?(Label::Base) for_labels.where(owner_id: owner.id) elsif owner.is_a?(Concept::Base) for_concepts.where(owner_id: owner.id) else raise "Note::Base.by_owner: Unknown owner (#{owner.inspect})" end end |
.by_owner_type(klass) ⇒ Object
61 62 63 |
# File 'app/models/note/base.rb', line 61 def self.by_owner_type(klass) where(owner_type: klass.is_a?(ActiveRecord::Base) ? klass.name : klass) end |
.by_query_value(query) ⇒ Object
57 58 59 |
# File 'app/models/note/base.rb', line 57 def self.by_query_value(query) where(["LOWER(#{table_name}.value) LIKE ?", query.to_s.downcase]) end |
.edit_partial_name(obj) ⇒ Object
115 116 117 |
# File 'app/models/note/base.rb', line 115 def self.edit_partial_name(obj) 'partials/note/edit_base' end |
.for_concepts ⇒ Object
65 66 67 |
# File 'app/models/note/base.rb', line 65 def self.for_concepts where(owner_type: 'Concept::Base') end |
.for_labels ⇒ Object
69 70 71 |
# File 'app/models/note/base.rb', line 69 def self.for_labels where(owner_type: 'Label::Base') end |
.partial_name(obj) ⇒ Object
111 112 113 |
# File 'app/models/note/base.rb', line 111 def self.partial_name(obj) 'partials/note/base' end |
.search_result_partial_name ⇒ Object
159 160 161 |
# File 'app/models/note/base.rb', line 159 def self.search_result_partial_name 'partials/note/search_result' end |
.single_query(params = {}) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/models/note/base.rb', line 119 def self.single_query(params = {}) query_str = build_query_string(params) scope = by_query_value(query_str). by_language(params[:languages].to_a) case params[:for] when 'concept' scope = scope.where('concepts.type' => Iqvoc::Concept.base_class_name) .references(:concepts) owner = :concept when 'collection' scope = scope.where('concepts.type' => Iqvoc::Collection.base_class_name) .references(:concepts) owner = :collection else # no additional conditions scope end if params[:collection_origin].present? collection = Collection::Base.where(origin: params[:collection_origin]).last if collection if owner scope = scope.includes(owner => :collection_members) else scope = scope.includes(:concept => :collection_members) .includes(:collection => :collection_members) end scope = scope.where("#{Collection::Member::Base.table_name}.collection_id" => collection.id) scope = scope.references(:collection_members) else raise "Collection with Origin #{params[:collection_origin]} not found!" end end scope = yield(scope) if block_given? scope.map { |result| SearchResult.new(result) } end |
.view_section(obj) ⇒ Object
103 104 105 |
# File 'app/models/note/base.rb', line 103 def self.view_section(obj) 'notes' end |
.view_section_sort_key(obj) ⇒ Object
107 108 109 |
# File 'app/models/note/base.rb', line 107 def self.view_section_sort_key(obj) 100 end |
Instance Method Details
#<=>(other) ⇒ Object
********** Methods
85 86 87 |
# File 'app/models/note/base.rb', line 85 def <=>(other) self.to_s.downcase <=> other.to_s.downcase end |
#build_search_result_rdf(document, result) ⇒ Object
163 164 165 166 |
# File 'app/models/note/base.rb', line 163 def build_search_result_rdf(document, result) result.Sdc::link(IqRdf.build_uri(owner.origin)) build_rdf(document, result) end |
#from_annotation_list!(str) ⇒ Object
TODO: This should move to umt because the “list” is more or less proprietary
90 91 92 93 94 95 96 97 |
# File 'app/models/note/base.rb', line 90 def from_annotation_list!(str) str.gsub(/\[|\]/, '').split('; ').map { |a| a.split(' ') }.each do |annotation| namespace, predicate = annotation.first.split(':', 2) annotations << Note::Annotated::Base.new(value: annotation.second, namespace: namespace, predicate: predicate) end self end |
#to_s ⇒ Object
99 100 101 |
# File 'app/models/note/base.rb', line 99 def to_s "#{self.value}" end |