Class: Languages::Language

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

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.

Parameters:

  • ({id: String, part2b: String?, part2t: String?, part1: String?, scope: "I" | "M" | "S", language_type: "A" | "C" | "E" | "H" | "L" | "S", ref_name: String})


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_1Symbol? (readonly) Also known as: alpha2

Returns the value of attribute iso639_1.

Returns:

  • (Symbol, nil)


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

def iso639_1
  @iso639_1
end

#iso639_2bSymbol? (readonly) Also known as: alpha3_bibliographic

Returns the value of attribute iso639_2b.

Returns:

  • (Symbol, nil)


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

def iso639_2b
  @iso639_2b
end

#iso639_2tSymbol? (readonly) Also known as: iso639_2, alpha3_terminology

Returns the value of attribute iso639_2t.

Returns:

  • (Symbol, nil)


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

def iso639_2t
  @iso639_2t
end

#iso639_3Symbol (readonly) Also known as: alpha3

Returns the value of attribute iso639_3.

Returns:

  • (Symbol)


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

def iso639_3
  @iso639_3
end

#macrolanguageLanguage? (readonly)

Returns the value of attribute macrolanguage.

Returns:



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

def macrolanguage
  @macrolanguage
end

#nameString (readonly)

Returns the value of attribute name.

Returns:

  • (String)


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

def name
  @name
end

#scopeSymbol? (readonly)

Returns the value of attribute scope.

Returns:

  • (Symbol, nil)


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

def scope
  @scope
end

#typeSymbol? (readonly)

Returns the value of attribute type.

Returns:

  • (Symbol, nil)


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

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Integer?

Parameters:

Returns:

  • (Integer, nil)


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

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

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

Parameters:

  • (Object)

Returns:

  • (Boolean)


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

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

#ancient?Boolean

Returns:

  • (Boolean)


81
# File 'sig/languages.rbs', line 81

def ancient?: () -> bool

#constructed?Boolean

Returns:

  • (Boolean)


82
# File 'sig/languages.rbs', line 82

def constructed?: () -> bool

#extinct?Boolean

Returns:

  • (Boolean)


83
# File 'sig/languages.rbs', line 83

def extinct?: () -> bool

#hashInteger

Returns:

  • (Integer)


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

def hash
  iso639_3.hash
end

#historical?Boolean

Returns:

  • (Boolean)


84
# File 'sig/languages.rbs', line 84

def historical?: () -> bool

#individual_language?Boolean

Returns:

  • (Boolean)


79
# File 'sig/languages.rbs', line 79

def individual_language?: () -> bool

#living?Boolean

Returns:

  • (Boolean)


85
# File 'sig/languages.rbs', line 85

def living?: () -> bool

#macrolanguage?Boolean

Returns:

  • (Boolean)


78
# File 'sig/languages.rbs', line 78

def macrolanguage?: () -> bool

#parse_scope(code) ⇒ Symbol?

Parameters:

  • code (String, nil)

    Single uppercase character representing the scope in ISO 639 data

Returns:

  • (Symbol, nil)


65
66
67
# File 'lib/languages/language.rb', line 65

def parse_scope(code)
  SCOPES.detect { |s| s.chr.upcase == code }&.to_sym
end

#parse_type(code) ⇒ Symbol?

Parameters:

  • code (String, nil)

    Single uppercase character representing the language type in ISO 639 data

Returns:

  • (Symbol, nil)


71
72
73
# File 'lib/languages/language.rb', line 71

def parse_type(code)
  TYPES.detect { |t| t.chr.upcase == code }&.to_sym
end

#special?Boolean

Returns:

  • (Boolean)


86
# File 'sig/languages.rbs', line 86

def special?: () -> bool

#special_language?Boolean

Returns:

  • (Boolean)


77
# File 'sig/languages.rbs', line 77

def special_language?: () -> bool

#to_sString

Returns:

  • (String)


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