Class: Language

Inherits:
ApplicationRecord show all
Includes:
Housekeeping::Timestamps, Housekeeping::Users, Shared::IsApplicationData, Shared::IsData
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)

Attributes included from Housekeeping::Users

#by

Class Method Summary (collapse)

Methods included from Housekeeping::Timestamps

#data_breakdown_for_chartkick_recent

Methods included from Housekeeping::Users

#set_created_by_id, #set_updated_by_id

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) alpha_2

Returns alpha_2 will have either a 2 character value or and empty string ('')

Returns:

  • (String)

    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
# 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
  has_many :sources, inverse_of: :source_language

  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)
    term = "#{params[:term]}%"
    where('english_name ILIKE ? OR english_name = ?', term, params[:term])
  end

end

- (String) alpha_3_bibiographic

Returns attribute alpha_3_bibliographic always has a distinct 3 character value

Returns:

  • (String)

    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
# 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
  has_many :sources, inverse_of: :source_language

  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)
    term = "#{params[:term]}%"
    where('english_name ILIKE ? OR english_name = ?', term, params[:term])
  end

end

- (String) alpha_3_terminologic

Returns:

  • (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
# 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
  has_many :sources, inverse_of: :source_language

  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)
    term = "#{params[:term]}%"
    where('english_name ILIKE ? OR english_name = ?', term, params[:term])
  end

end

- (String) english_name

Returns english_name may be more than one word long (e.g. 'English, Middle (1100-1500)', 'Filipino; Pilipino','Finno-Ugrian languages')

Returns:

  • (String)

    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
# 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
  has_many :sources, inverse_of: :source_language

  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)
    term = "#{params[:term]}%"
    where('english_name ILIKE ? OR english_name = ?', term, params[:term])
  end

end

- (String) french_name

Returns french_name may be more than one word long

Returns:

  • (String)

    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
# 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
  has_many :sources, inverse_of: :source_language

  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)
    term = "#{params[:term]}%"
    where('english_name ILIKE ? OR english_name = ?', term, params[:term])
  end

end

Class Method Details

+ (Object) find_for_autocomplete(params)



45
46
47
48
# File 'app/models/language.rb', line 45

def self.find_for_autocomplete(params)
  term = "#{params[:term]}%"
  where('english_name ILIKE ? OR english_name = ?', term, params[:term])
end

+ (Object) with_english_name_or_abbreviation(value)



34
35
36
37
38
39
40
41
42
43
# File 'app/models/language.rb', line 34

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