Class: Webgen::Language

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

Overview

Describes a human language which is uniquely identfied by a three letter code and, optionally, by an alternative three letter or a two letter code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(codes, description) ⇒ Language

Create a new language. codes has to be an array containing three strings: the three letter code, the alternative three letter code and the two letter code. If one is not available for the language, it has to be nil.



18
19
20
21
# File 'lib/webgen/languages.rb', line 18

def initialize(codes, description)
  @codes = codes
  @description = description
end

Instance Attribute Details

#codesObject (readonly)

An array containing the language codes for the language.



10
11
12
# File 'lib/webgen/languages.rb', line 10

def codes
  @codes
end

#descriptionObject (readonly)

The english description of the language.



13
14
15
# File 'lib/webgen/languages.rb', line 13

def description
  @description
end

Instance Method Details

#<=>(other) ⇒ Object

:nodoc:



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

def <=>(other) #:nodoc:
  self.to_s <=> other.to_s
end

#code2charsObject

The two letter code.



24
25
26
# File 'lib/webgen/languages.rb', line 24

def code2chars
  @codes[2]
end

#code3charsObject

The three letter code.



29
30
31
# File 'lib/webgen/languages.rb', line 29

def code3chars
  @codes[0]
end

#code3chars_alternativeObject

The alternative three letter code.



34
35
36
# File 'lib/webgen/languages.rb', line 34

def code3chars_alternative
  @codes[1]
end

#inspectObject

:nodoc:



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

def inspect #:nodoc:
  "#<Language codes=#{codes.inspect} description=#{description.inspect}>"
end

#to_sObject Also known as: to_str

The textual representation of the language.



39
40
41
# File 'lib/webgen/languages.rb', line 39

def to_s
  code2chars || code3chars
end