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.



20
21
22
23
# File 'lib/webgen/languages.rb', line 20

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

Instance Attribute Details

#codesObject (readonly)

An array containing the language codes for the language.



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

def codes
  @codes
end

#descriptionObject (readonly)

The english description of the language.



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

def description
  @description
end

Instance Method Details

#<=>(other) ⇒ Object

:nodoc:



51
52
53
# File 'lib/webgen/languages.rb', line 51

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

#code2charsObject

The two letter code.



26
27
28
# File 'lib/webgen/languages.rb', line 26

def code2chars
  @codes[2]
end

#code3charsObject

The three letter code.



31
32
33
# File 'lib/webgen/languages.rb', line 31

def code3chars
  @codes[0]
end

#code3chars_alternativeObject

The alternative three letter code.



36
37
38
# File 'lib/webgen/languages.rb', line 36

def code3chars_alternative
  @codes[1]
end

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/webgen/languages.rb', line 55

def eql?(other) #:nodoc:
  (other.is_a?(self.class) && other.to_s == self.to_s) ||
    (other.is_a?(String) && self.to_s == other)
end

#hashObject

:nodoc:



60
61
62
# File 'lib/webgen/languages.rb', line 60

def hash #:nodoc:
  self.to_s.hash
end

#inspectObject

:nodoc:



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

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

#to_sObject Also known as: to_str

The textual representation of the language.



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

def to_s
  code2chars || code3chars
end