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. attribute alpha_3_bibliographic always has a distinct 3 character value alpha_2 will have either a 2 character value or and empty string ('') english_name or french_name may be more than one word long (e.g. 'English, Middle (1100-1500)', 'Filipino; Pilipino','Finno-Ugrian languages') and 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

Instance Attribute Details

- (String) alpha_2

TODO:

Returns:

  • (String)


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
# File 'app/models/language.rb', line 29

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

  # Scopes
  scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")}  # non-case sensitive comparison

  #Validations
  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

TODO:

Returns:

  • (String)


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
# File 'app/models/language.rb', line 29

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

  # Scopes
  scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")}  # non-case sensitive comparison

  #Validations
  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

TODO:

Returns:

  • (String)


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
# File 'app/models/language.rb', line 29

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

  # Scopes
  scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")}  # non-case sensitive comparison

  #Validations
  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

TODO:

Returns:

  • (String)


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
# File 'app/models/language.rb', line 29

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

  # Scopes
  scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")}  # non-case sensitive comparison

  #Validations
  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

TODO:

Returns:

  • (String)


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
# File 'app/models/language.rb', line 29

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

  # Scopes
  scope :with_english_name_containing, ->(name) {where('english_name ILIKE ?', "%#{name}%")}  # non-case sensitive comparison

  #Validations
  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)



57
58
59
60
# File 'app/models/language.rb', line 57

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)



45
46
47
48
49
50
51
52
53
54
55
# 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