Class: Label::Base
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Label::Base
- Defined in:
- app/models/label/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
- .begins_with(prefix) ⇒ 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
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #expired? ⇒ Boolean
- #hash ⇒ Object
-
#published? ⇒ Boolean
********* Methods.
- #to_literal ⇒ Object
- #to_s ⇒ Object
Class Method Details
.begins_with(prefix) ⇒ Object
62 63 64 65 66 67 |
# File 'app/models/label/base.rb', line 62 def self.begins_with(prefix) prefix = prefix.to_s table = Label::Base.table_name where("LOWER(SUBSTR(#{table}.value, 1, :length)) = :prefix", length: prefix.length, prefix: prefix.downcase) end |
.by_language(lang_code) ⇒ Object
********* Scopes
51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/label/base.rb', line 51 def self.by_language(lang_code) lang_code = nil if lang_code.to_s == 'none' if (lang_code.is_a?(Array) && lang_code.include?('none')) 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
84 85 86 |
# File 'app/models/label/base.rb', line 84 def self.by_query_value(query) where(["#{table_name}.value ILIKE ?", query.mb_chars.downcase.to_s]) end |
.missing_translation(lang, main_lang) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/label/base.rb', line 69 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!
90 91 92 |
# File 'app/models/label/base.rb', line 90 def self.published where(arel_table[:published_at].not_eq(nil)) end |
.unpublished ⇒ Object
94 95 96 |
# File 'app/models/label/base.rb', line 94 def self.unpublished where(arel_table[:published_at].eq(nil)) end |
Instance Method Details
#<=>(other) ⇒ Object
108 109 110 |
# File 'app/models/label/base.rb', line 108 def <=>(other) self.to_s.downcase <=> other.to_s.downcase end |
#==(other) ⇒ Object
112 113 114 |
# File 'app/models/label/base.rb', line 112 def ==(other) language == other.try(:language) && value == other.try(:value) end |
#eql?(other) ⇒ Boolean
116 117 118 |
# File 'app/models/label/base.rb', line 116 def eql?(other) self == other end |
#expired? ⇒ Boolean
104 105 106 |
# File 'app/models/label/base.rb', line 104 def expired? self.expired_at && self.expired_at < Date.today end |
#hash ⇒ Object
120 121 122 |
# File 'app/models/label/base.rb', line 120 def hash [value, language].hash end |
#published? ⇒ Boolean
********* Methods
100 101 102 |
# File 'app/models/label/base.rb', line 100 def published? true end |
#to_literal ⇒ Object
124 125 126 |
# File 'app/models/label/base.rb', line 124 def to_literal "\"#{value}\"@#{language}" end |
#to_s ⇒ Object
128 129 130 |
# File 'app/models/label/base.rb', line 128 def to_s value.to_s end |