Class: Label::Base
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Label::Base
- Defined in:
- app/models/label/base.rb
Overview
Copyright 2011 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
- .begins_with(letter) ⇒ Object
-
.by_language(lang_code) ⇒ Object
********* Scopes.
- .by_query_value(query) ⇒ Object
- .missing_translation(lang, main_lang) ⇒ Object
-
.published ⇒ Object
Attention: This means that even label classes without version controll will also have to set the published_at flag to be recognized as published!.
- .unpublished ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#published? ⇒ Boolean
********* Methods.
- #to_literal ⇒ Object
- #to_s ⇒ Object
Class Method Details
.begins_with(letter) ⇒ Object
45 46 47 |
# File 'app/models/label/base.rb', line 45 def self.begins_with(letter) where("LOWER(SUBSTR(#{Label::Base.table_name}.value, 1, 1)) = :letter", :letter => letter.to_s.downcase) end |
.by_language(lang_code) ⇒ Object
********* Scopes
35 36 37 38 39 40 41 42 43 |
# File 'app/models/label/base.rb', line 35 def self.by_language(lang_code) if (lang_code.is_a?(Array) && lang_code.include?(nil)) where(arel_table[:language].eq(nil).or(arel_table[:language].in(lang_code.compact))) elsif lang_code.blank? where(arel_table[:language].eq(nil)) else where(:language => lang_code) end end |
.by_query_value(query) ⇒ Object
64 65 66 |
# File 'app/models/label/base.rb', line 64 def self.by_query_value(query) where(["LOWER(#{table_name}.value) LIKE ?", query.to_s.downcase]) end |
.missing_translation(lang, main_lang) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/label/base.rb', line 49 def self.missing_translation(lang, main_lang) joins(:concepts). joins(sanitize_sql(["LEFT OUTER JOIN labelings pref_labelings ON pref_labelings.id <> labelings.id AND pref_labelings.owner_id = concepts.id AND pref_labelings.type = '%s'", Iqvoc::Concept.pref_labeling_class_name])). joins(sanitize_sql(["LEFT OUTER JOIN labels pref_labels ON pref_labels.id = pref_labelings.target_id AND pref_labels.language = '%s'", lang])). where('labelings.type = :class_name', :class_name => Iqvoc::Concept.pref_labeling_class_name). where('pref_labels.id IS NULL'). where('labels.language = :lang', :lang => main_lang). includes(:pref_labeled_concepts) end |
.published ⇒ Object
Attention: This means that even label classes without version controll will also have to set the published_at flag to be recognized as published!
70 71 72 |
# File 'app/models/label/base.rb', line 70 def self.published where(arel_table[:published_at].not_eq(nil)) end |
.unpublished ⇒ Object
74 75 76 |
# File 'app/models/label/base.rb', line 74 def self.unpublished where(arel_table[:published_at].eq(nil)) end |
Instance Method Details
#<=>(other) ⇒ Object
84 85 86 |
# File 'app/models/label/base.rb', line 84 def <=>(other) self.to_s.downcase <=> other.to_s.downcase end |
#published? ⇒ Boolean
********* Methods
80 81 82 |
# File 'app/models/label/base.rb', line 80 def published? true end |
#to_literal ⇒ Object
88 89 90 |
# File 'app/models/label/base.rb', line 88 def to_literal "\"#{value}\"@#{language}" end |
#to_s ⇒ Object
92 93 94 95 96 97 98 |
# File 'app/models/label/base.rb', line 92 def to_s if language.to_s != I18n.locale.to_s.strip value.to_s + " [#{I18n.t("txt.common.translation_missing_for")} '#{I18n.locale.to_s.strip}']" else value.to_s end end |