Module: Language
- Includes:
- ActiveSupport::Concern
- Defined in:
- app/models/concern/language.rb
Constant Summary collapse
- LANGUAGE_TREE =
:nodoc:
{- OPTIONS =
:nodoc:
i(novalidate on)
Class Method Summary collapse
-
.alphabeth_list ⇒ Object
alphabeth_listreturns list of available languages. -
.alphabeth_list_for(language_code) ⇒ Object
alphabeth_list_forreturns list of available alphabeths for the specified language code. -
.language_list ⇒ Object
language_listreturns list of available languages. -
.language_list_for(alphabeth_code) ⇒ Object
language_list_forreturns the language list for the specified alphabeth code.
Instance Method Summary collapse
-
#has_alphabeth(options = {}) ⇒ Object
has_alphabethsets up alphabeth feature on a column or itself model, i.e.
Class Method Details
.alphabeth_list ⇒ Object
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_list ⇒ Object
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.each do |o| self.send( "setup_#{o}", [ o ] ) ;end ;end |