Class: LanguageList::LanguageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/language_list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ LanguageInfo

Returns a new instance of LanguageInfo.



7
8
9
10
11
12
13
14
15
16
# File 'lib/language_list.rb', line 7

def initialize(options)
  @name = options[:name]
  @common_name = options[:common_name]
  @iso_639_3 = options[:iso_639_3]
  @iso_639_1 = options[:iso_639_1]
  @iso_639_2b = options[:iso_639_2b]
  @iso_639_2t = options[:iso_639_2t]
  @common = options[:common]
  @type = options[:type]
end

Instance Attribute Details

#iso_639_1Object (readonly)

Returns the value of attribute iso_639_1.



5
6
7
# File 'lib/language_list.rb', line 5

def iso_639_1
  @iso_639_1
end

#iso_639_2bObject (readonly)

Returns the value of attribute iso_639_2b.



5
6
7
# File 'lib/language_list.rb', line 5

def iso_639_2b
  @iso_639_2b
end

#iso_639_2tObject (readonly)

Returns the value of attribute iso_639_2t.



5
6
7
# File 'lib/language_list.rb', line 5

def iso_639_2t
  @iso_639_2t
end

#iso_639_3Object (readonly)

Returns the value of attribute iso_639_3.



5
6
7
# File 'lib/language_list.rb', line 5

def iso_639_3
  @iso_639_3
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/language_list.rb', line 5

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/language_list.rb', line 5

def type
  @type
end

Class Method Details

.find(code) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/language_list.rb', line 66

def self.find(code)
  return if code.nil?
  
  code = code.downcase
  find_by_iso_639_1(code) ||
    find_by_iso_639_3(code) ||
    find_by_iso_639_2b(code) ||
    find_by_iso_639_2t(code) ||
    find_by_name(code)
end

.find_by_iso_639_1(code) ⇒ Object



44
45
46
# File 'lib/language_list.rb', line 44

def self.find_by_iso_639_1(code)
  LanguageList::BY_ISO_639_1[code]
end

.find_by_iso_639_2b(code) ⇒ Object



52
53
54
# File 'lib/language_list.rb', line 52

def self.find_by_iso_639_2b(code)
  LanguageList::BY_ISO_639_2B[code]
end

.find_by_iso_639_2t(code) ⇒ Object



56
57
58
# File 'lib/language_list.rb', line 56

def self.find_by_iso_639_2t(code)
  LanguageList::BY_ISO_639_2T[code]
end

.find_by_iso_639_3(code) ⇒ Object



48
49
50
# File 'lib/language_list.rb', line 48

def self.find_by_iso_639_3(code)
  LanguageList::BY_ISO_639_3[code]
end

.find_by_name(name) ⇒ Object



60
61
62
63
64
# File 'lib/language_list.rb', line 60

def self.find_by_name(name)
  return if name.nil?
  
  LanguageList::BY_NAME[name.downcase]
end

Instance Method Details

#<=>(other) ⇒ Object



26
27
28
# File 'lib/language_list.rb', line 26

def <=>(other)
  self.name <=> other.name
end

#common?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/language_list.rb', line 22

def common?
  @common
end

#common_nameObject



18
19
20
# File 'lib/language_list.rb', line 18

def common_name
  @common_name || @name
end

#iso_639_1?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/language_list.rb', line 30

def iso_639_1?
  !@iso_639_1.nil?
end

#to_sObject



40
41
42
# File 'lib/language_list.rb', line 40

def to_s
  "#{@iso_639_3}#{" (#{@iso_639_1})" if @iso_639_1} - #{@name}"
end