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
# File 'lib/language_list.rb', line 7

def initialize(options)
  @name = options[:name]
  @iso_639_3 = options[:iso_639_3]
  @iso_639_1 = options[:iso_639_1]
  @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_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



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

def self.find(code)
  find_by_iso_639_1(code) || find_by_iso_639_3(code) || find_by_name(code)
end

.find_by_iso_639_1(code) ⇒ Object



37
38
39
# File 'lib/language_list.rb', line 37

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

.find_by_iso_639_3(code) ⇒ Object



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

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

.find_by_name(name) ⇒ Object



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

def self.find_by_name(name)
  LanguageList::BY_NAME[name]
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#common?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/language_list.rb', line 15

def common?
  @common
end

#iso_639_1?Boolean

Returns:

  • (Boolean)


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

def iso_639_1?
  !@iso_639_1.nil?
end

#to_sObject



33
34
35
# File 'lib/language_list.rb', line 33

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