Class: Languages::Language

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/languages/language.rb

Overview

Language defined in ISO 639-3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(csv_attributes) ⇒ Language

Returns a new instance of Language.



10
11
12
13
14
15
16
17
18
# File 'lib/languages/language.rb', line 10

def initialize(csv_attributes)
  @iso639_3 = csv_attributes.fetch(:id).to_sym
  @iso639_2b = csv_attributes.fetch(:part2b)&.to_sym
  @iso639_2t = csv_attributes.fetch(:part2t)&.to_sym
  @iso639_1 = csv_attributes.fetch(:part1)&.to_sym
  @scope = parse_scope(csv_attributes.fetch(:scope))
  @type = parse_type(csv_attributes.fetch(:language_type))
  @name = csv_attributes.fetch(:ref_name)
end

Instance Attribute Details

#iso639_1Object (readonly) Also known as: alpha2

Returns the value of attribute iso639_1.



8
9
10
# File 'lib/languages/language.rb', line 8

def iso639_1
  @iso639_1
end

#iso639_2bObject (readonly) Also known as: alpha3_bibliographic

Returns the value of attribute iso639_2b.



8
9
10
# File 'lib/languages/language.rb', line 8

def iso639_2b
  @iso639_2b
end

#iso639_2tObject (readonly) Also known as: iso639_2, alpha3_terminology

Returns the value of attribute iso639_2t.



8
9
10
# File 'lib/languages/language.rb', line 8

def iso639_2t
  @iso639_2t
end

#iso639_3Object (readonly) Also known as: alpha3

Returns the value of attribute iso639_3.



8
9
10
# File 'lib/languages/language.rb', line 8

def iso639_3
  @iso639_3
end

#macrolanguageObject (readonly)

Returns the value of attribute macrolanguage.



8
9
10
# File 'lib/languages/language.rb', line 8

def macrolanguage
  @macrolanguage
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/languages/language.rb', line 8

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



8
9
10
# File 'lib/languages/language.rb', line 8

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/languages/language.rb', line 8

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object



57
58
59
# File 'lib/languages/language.rb', line 57

def <=>(other)
  iso639_3 <=> other.iso639_3
end

#==(other) ⇒ Object Also known as: eql?



47
48
49
# File 'lib/languages/language.rb', line 47

def ==(other)
  other.class == self.class && other.iso639_3 == iso639_3
end

#hashObject



53
54
55
# File 'lib/languages/language.rb', line 53

def hash
  iso639_3.hash
end

#to_sObject



28
29
30
# File 'lib/languages/language.rb', line 28

def to_s
  name.to_s # Enforce return of String, even if name is nil
end