Module: Language

Includes:
ActiveSupport::Concern
Included in:
Calendary, Canto, Description, EventKind, Link, Name, Order, Service
Defined in:
app/models/concern/language.rb

Constant Summary collapse

LANGUAGE_TREE =

:nodoc:

{
   ру: %i(рп ру),
   цс: %i(цс рп ру цр),
   сс: :сс,
   сц: :сц,
   ук: :ук,
   бл: :бл,
   мк: :мк,
   сх: %i(ср хр),
   со: :со,
   бг: :бг,
   чх: :чх,
   сл: :сл,
   по: :по,
   кш: :кш,
   вл: :вл,
   нл: :нл,
   ар: :ар,
   ив: :ив,
   рм: %i(рм цу цр),
   гр: :гр,
   ла: :ла,
   ит: :ит,
   фр: :фр,
   ис: :ис,
   не: :не,
   ир: :ир,
   си: :си,
   ан: %i(ан са ра)
}
OPTIONS =

:nodoc:

%i(novalidate on)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.alphabeth_listObject

alphabeth_list returns list of available languages.



51
52
# File 'app/models/concern/language.rb', line 51

def self.alphabeth_list
Language::LANGUAGE_TREE.values.flatten.uniq ;end

.alphabeth_list_for(language_code) ⇒ Object

alphabeth_list_for returns list of available alphabeths for the specified language code.

Example:

validates :alphabeth_code, inclusion: { in: proc { |l|
   Language.alphabeth_list_for( l.language_code ) } } ; end


62
63
64
# File 'app/models/concern/language.rb', line 62

def self.alphabeth_list_for language_code
      [ Language::LANGUAGE_TREE[ language_code.to_s.to_sym ] ].flatten
.map( &:to_s ) ;end

.language_listObject

language_list returns list of available languages.

Example:

validates :language_code, inclusion: { in: Language.language_list }


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

def self.language_list
list = Language::LANGUAGE_TREE.keys
list.concat( list.map( &:to_s ) ) ;end

.language_list_for(alphabeth_code) ⇒ Object

language_list_for returns the language list for the specified alphabeth code.

Example:

validates :language_code, inclusion: { in: proc { |l|
   Language.language_list_for( l.alphabeth_code ) } } ; end


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/concern/language.rb', line 74

def self.language_list_for alphabeth_code
language_codes =
Language::LANGUAGE_TREE.invert.map do |(alphs, lang)|
   [ alphs ].flatten.map do |a|
      [a, lang] ;end;end
.flatten(1).reduce({}) do |h, (alph, lang)|
   case h[alph]
   when NilClass
      h[alph] = lang
   when Array
      h[alph] << lang
   else
      h[alph] = [ h[alph], lang ] ;end
   h ;end
.[](alphabeth_code.to_sym)
   
[ language_codes ].flatten.compact.map( &:to_s ) ;end

Instance Method Details

#has_alphabeth(options = {}) ⇒ Object

has_alphabeth sets up alphabeth feature on a column or itself model, i.e. generally alphabeth_code, and language_code fields to match text of the specified columns if any.

Examples:

has_alphabeth on: name: true
has_alphabeth on: { text: [:nosyntax, allow: " ‑" ] }
has_alphabeth on: [ :name, :text ]
has_alphabeth novalidate: true


103
104
105
# File 'app/models/concern/language.rb', line 103

def has_alphabeth options = {}
      OPTIONS.each do |o|
self.send( "setup_#{o}", options[ o ] ) ;end ;end