Class: Transfluent::Language

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

Overview

Represents a language that can be identified by an IETF language tag or Transfluent specific id

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, code, name) ⇒ Language



27
28
29
30
31
# File 'lib/transfluent/language.rb', line 27

def initialize id, code, name
  @id = id.to_i
  @code = code
  @name = name
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.get(code) ⇒ Language

Get an instance of language by code



15
16
17
18
19
# File 'lib/transfluent/language.rb', line 15

def self.get code
  Language.fetch if $languages_by_code.nil?

  $languages_by_code[code]
end

.get_by_id(id) ⇒ Object



21
22
23
24
25
# File 'lib/transfluent/language.rb', line 21

def self.get_by_id id
  Language.fetch if $languages_by_code.nil?

  $languages_by_id[id]
end