Class: Language
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Language
- Defined in:
- app/models/language.rb
Overview
This is a 1:1 representation of ISO 639-2. It is built on initialization with a rake task, and not further touched. Many of the languages have multiple version (e.g. there are 4 variations of German)
Instance Attribute Summary collapse
-
#alpha_2 ⇒ String
Alpha_2 will have either a 2 character value or and empty string (”).
-
#alpha_3_bibiographic ⇒ String
Attribute alpha_3_bibliographic always has a distinct 3 character value.
- #alpha_3_terminologic ⇒ String
-
#english_name ⇒ String
English_name may be more than one word long (e.g. ‘English, Middle (1100-1500)’, ‘Filipino; Pilipino’,‘Finno-Ugrian languages’).
-
#french_name ⇒ String
French_name may be more than one word long.
Attributes included from Housekeeping::Users
Class Method Summary collapse
- .find_for_autocomplete(params) ⇒ Object
- .select_optimized(user_id, project_id, klass = 'Source') ⇒ Object
- .with_english_name_or_abbreviation(value) ⇒ Object
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Housekeeping::Users
#set_created_by_id, #set_updated_by_id
Methods inherited from ApplicationRecord
Instance Attribute Details
#alpha_2 ⇒ String
Returns alpha_2 will have either a 2 character value or and empty string (”).
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/language.rb', line 21 class Language < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::IsData include Shared::IsApplicationData has_many :serials, inverse_of: :language, foreign_key: :primary_language_id has_many :sources, inverse_of: :source_language, class_name: 'Source::Bibtex' has_many :alternate_value_translations, class_name: 'AlternateValue::Translation' has_many :common_names, inverse_of: :language scope :used_recently_on_sources, -> { joins(sources: [:project_sources]).includes(sources: [:project_sources]).where(sources: { updated_at: 10.weeks.ago..Time.now } ).order('"sources"."updated_at" DESC') } # TODO: dry scope :used_recently_on_serials, -> { joins(:serials).includes(:serials).where(serials: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_common_names, -> { joins(:common_names).includes(:common_names).where(common_names: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_alternate_values, -> { joins(:alternate_value_translations).includes(:alternate_value_translations).where(alternate_values: { updated_at: 10.weeks.ago..Time.now } ).order('"alternate_values"."updated_at" DESC') } scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")} # non-case sensitive comparison validates_presence_of :english_name, :alpha_3_bibliographic def self.with_english_name_or_abbreviation(value) value = [value] if value.class == String t = Language.arel_table a = t[:english_name].matches_any(value) b = t[:alpha_2].matches_any(value) c = t[:alpha_3_bibliographic].matches_any(value) d = t[:alpha_3_terminologic].matches_any(value) Language.where(a.or(b).or(c).or(d).to_sql) end def self.find_for_autocomplete(params) where('english_name ILIKE ? OR english_name = ?', "#{params[:term]}%", params[:term]) end # @param klass ['Source' || 'Serial'] def self.select_optimized(user_id, project_id, klass = 'Source') language_ids = case klass when 'Source' Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).pluck(:id).uniq when 'Serial' Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).pluck(:id).uniq when 'AlternateValue' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq when 'CommonNames' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq end h = { recent: Language.where(id: language_ids.first(10)).order(:english_name).to_a, pinboard: Language.pinned_by(user_id).pinned_in_project(project_id).to_a, quick: (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + Language.where(id: language_ids.first(4)).order(:english_name).to_a).uniq } h end end |
#alpha_3_bibiographic ⇒ String
Returns attribute alpha_3_bibliographic always has a distinct 3 character value.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/language.rb', line 21 class Language < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::IsData include Shared::IsApplicationData has_many :serials, inverse_of: :language, foreign_key: :primary_language_id has_many :sources, inverse_of: :source_language, class_name: 'Source::Bibtex' has_many :alternate_value_translations, class_name: 'AlternateValue::Translation' has_many :common_names, inverse_of: :language scope :used_recently_on_sources, -> { joins(sources: [:project_sources]).includes(sources: [:project_sources]).where(sources: { updated_at: 10.weeks.ago..Time.now } ).order('"sources"."updated_at" DESC') } # TODO: dry scope :used_recently_on_serials, -> { joins(:serials).includes(:serials).where(serials: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_common_names, -> { joins(:common_names).includes(:common_names).where(common_names: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_alternate_values, -> { joins(:alternate_value_translations).includes(:alternate_value_translations).where(alternate_values: { updated_at: 10.weeks.ago..Time.now } ).order('"alternate_values"."updated_at" DESC') } scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")} # non-case sensitive comparison validates_presence_of :english_name, :alpha_3_bibliographic def self.with_english_name_or_abbreviation(value) value = [value] if value.class == String t = Language.arel_table a = t[:english_name].matches_any(value) b = t[:alpha_2].matches_any(value) c = t[:alpha_3_bibliographic].matches_any(value) d = t[:alpha_3_terminologic].matches_any(value) Language.where(a.or(b).or(c).or(d).to_sql) end def self.find_for_autocomplete(params) where('english_name ILIKE ? OR english_name = ?', "#{params[:term]}%", params[:term]) end # @param klass ['Source' || 'Serial'] def self.select_optimized(user_id, project_id, klass = 'Source') language_ids = case klass when 'Source' Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).pluck(:id).uniq when 'Serial' Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).pluck(:id).uniq when 'AlternateValue' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq when 'CommonNames' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq end h = { recent: Language.where(id: language_ids.first(10)).order(:english_name).to_a, pinboard: Language.pinned_by(user_id).pinned_in_project(project_id).to_a, quick: (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + Language.where(id: language_ids.first(4)).order(:english_name).to_a).uniq } h end end |
#alpha_3_terminologic ⇒ String
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/language.rb', line 21 class Language < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::IsData include Shared::IsApplicationData has_many :serials, inverse_of: :language, foreign_key: :primary_language_id has_many :sources, inverse_of: :source_language, class_name: 'Source::Bibtex' has_many :alternate_value_translations, class_name: 'AlternateValue::Translation' has_many :common_names, inverse_of: :language scope :used_recently_on_sources, -> { joins(sources: [:project_sources]).includes(sources: [:project_sources]).where(sources: { updated_at: 10.weeks.ago..Time.now } ).order('"sources"."updated_at" DESC') } # TODO: dry scope :used_recently_on_serials, -> { joins(:serials).includes(:serials).where(serials: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_common_names, -> { joins(:common_names).includes(:common_names).where(common_names: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_alternate_values, -> { joins(:alternate_value_translations).includes(:alternate_value_translations).where(alternate_values: { updated_at: 10.weeks.ago..Time.now } ).order('"alternate_values"."updated_at" DESC') } scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")} # non-case sensitive comparison validates_presence_of :english_name, :alpha_3_bibliographic def self.with_english_name_or_abbreviation(value) value = [value] if value.class == String t = Language.arel_table a = t[:english_name].matches_any(value) b = t[:alpha_2].matches_any(value) c = t[:alpha_3_bibliographic].matches_any(value) d = t[:alpha_3_terminologic].matches_any(value) Language.where(a.or(b).or(c).or(d).to_sql) end def self.find_for_autocomplete(params) where('english_name ILIKE ? OR english_name = ?', "#{params[:term]}%", params[:term]) end # @param klass ['Source' || 'Serial'] def self.select_optimized(user_id, project_id, klass = 'Source') language_ids = case klass when 'Source' Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).pluck(:id).uniq when 'Serial' Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).pluck(:id).uniq when 'AlternateValue' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq when 'CommonNames' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq end h = { recent: Language.where(id: language_ids.first(10)).order(:english_name).to_a, pinboard: Language.pinned_by(user_id).pinned_in_project(project_id).to_a, quick: (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + Language.where(id: language_ids.first(4)).order(:english_name).to_a).uniq } h end end |
#english_name ⇒ String
Returns english_name may be more than one word long (e.g. ‘English, Middle (1100-1500)’, ‘Filipino; Pilipino’,‘Finno-Ugrian languages’).
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/language.rb', line 21 class Language < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::IsData include Shared::IsApplicationData has_many :serials, inverse_of: :language, foreign_key: :primary_language_id has_many :sources, inverse_of: :source_language, class_name: 'Source::Bibtex' has_many :alternate_value_translations, class_name: 'AlternateValue::Translation' has_many :common_names, inverse_of: :language scope :used_recently_on_sources, -> { joins(sources: [:project_sources]).includes(sources: [:project_sources]).where(sources: { updated_at: 10.weeks.ago..Time.now } ).order('"sources"."updated_at" DESC') } # TODO: dry scope :used_recently_on_serials, -> { joins(:serials).includes(:serials).where(serials: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_common_names, -> { joins(:common_names).includes(:common_names).where(common_names: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_alternate_values, -> { joins(:alternate_value_translations).includes(:alternate_value_translations).where(alternate_values: { updated_at: 10.weeks.ago..Time.now } ).order('"alternate_values"."updated_at" DESC') } scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")} # non-case sensitive comparison validates_presence_of :english_name, :alpha_3_bibliographic def self.with_english_name_or_abbreviation(value) value = [value] if value.class == String t = Language.arel_table a = t[:english_name].matches_any(value) b = t[:alpha_2].matches_any(value) c = t[:alpha_3_bibliographic].matches_any(value) d = t[:alpha_3_terminologic].matches_any(value) Language.where(a.or(b).or(c).or(d).to_sql) end def self.find_for_autocomplete(params) where('english_name ILIKE ? OR english_name = ?', "#{params[:term]}%", params[:term]) end # @param klass ['Source' || 'Serial'] def self.select_optimized(user_id, project_id, klass = 'Source') language_ids = case klass when 'Source' Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).pluck(:id).uniq when 'Serial' Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).pluck(:id).uniq when 'AlternateValue' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq when 'CommonNames' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq end h = { recent: Language.where(id: language_ids.first(10)).order(:english_name).to_a, pinboard: Language.pinned_by(user_id).pinned_in_project(project_id).to_a, quick: (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + Language.where(id: language_ids.first(4)).order(:english_name).to_a).uniq } h end end |
#french_name ⇒ String
Returns french_name may be more than one word long.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/language.rb', line 21 class Language < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::IsData include Shared::IsApplicationData has_many :serials, inverse_of: :language, foreign_key: :primary_language_id has_many :sources, inverse_of: :source_language, class_name: 'Source::Bibtex' has_many :alternate_value_translations, class_name: 'AlternateValue::Translation' has_many :common_names, inverse_of: :language scope :used_recently_on_sources, -> { joins(sources: [:project_sources]).includes(sources: [:project_sources]).where(sources: { updated_at: 10.weeks.ago..Time.now } ).order('"sources"."updated_at" DESC') } # TODO: dry scope :used_recently_on_serials, -> { joins(:serials).includes(:serials).where(serials: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_common_names, -> { joins(:common_names).includes(:common_names).where(common_names: { updated_at: 10.weeks.ago..Time.now } ).order('"serials"."updated_at" DESC') } scope :used_recently_on_alternate_values, -> { joins(:alternate_value_translations).includes(:alternate_value_translations).where(alternate_values: { updated_at: 10.weeks.ago..Time.now } ).order('"alternate_values"."updated_at" DESC') } scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")} # non-case sensitive comparison validates_presence_of :english_name, :alpha_3_bibliographic def self.with_english_name_or_abbreviation(value) value = [value] if value.class == String t = Language.arel_table a = t[:english_name].matches_any(value) b = t[:alpha_2].matches_any(value) c = t[:alpha_3_bibliographic].matches_any(value) d = t[:alpha_3_terminologic].matches_any(value) Language.where(a.or(b).or(c).or(d).to_sql) end def self.find_for_autocomplete(params) where('english_name ILIKE ? OR english_name = ?', "#{params[:term]}%", params[:term]) end # @param klass ['Source' || 'Serial'] def self.select_optimized(user_id, project_id, klass = 'Source') language_ids = case klass when 'Source' Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).pluck(:id).uniq when 'Serial' Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).pluck(:id).uniq when 'AlternateValue' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq when 'CommonNames' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq end h = { recent: Language.where(id: language_ids.first(10)).order(:english_name).to_a, pinboard: Language.pinned_by(user_id).pinned_in_project(project_id).to_a, quick: (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + Language.where(id: language_ids.first(4)).order(:english_name).to_a).uniq } h end end |
Class Method Details
.find_for_autocomplete(params) ⇒ Object
56 57 58 |
# File 'app/models/language.rb', line 56 def self.find_for_autocomplete(params) where('english_name ILIKE ? OR english_name = ?', "#{params[:term]}%", params[:term]) end |
.select_optimized(user_id, project_id, klass = 'Source') ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/language.rb', line 61 def self.select_optimized(user_id, project_id, klass = 'Source') language_ids = case klass when 'Source' Language.used_recently_on_sources.where('project_sources.project_id = ? AND sources.updated_by_id = ?', project_id, user_id).pluck(:id).uniq when 'Serial' Language.used_recently_on_serials.where('serials.updated_by_id = ?', user_id).pluck(:id).uniq when 'AlternateValue' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq when 'CommonNames' Language.used_recently_on_alternate_values.where('alternate_values.updated_by_id = ?', user_id).pluck(:id).uniq end h = { recent: Language.where(id: language_ids.first(10)).order(:english_name).to_a, pinboard: Language.pinned_by(user_id).pinned_in_project(project_id).to_a, quick: (Language.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a + Language.where(id: language_ids.first(4)).order(:english_name).to_a).uniq } h end |
.with_english_name_or_abbreviation(value) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/language.rb', line 45 def self.with_english_name_or_abbreviation(value) value = [value] if value.class == String t = Language.arel_table a = t[:english_name].matches_any(value) b = t[:alpha_2].matches_any(value) c = t[:alpha_3_bibliographic].matches_any(value) d = t[:alpha_3_terminologic].matches_any(value) Language.where(a.or(b).or(c).or(d).to_sql) end |