Class: Webgen::Language
- Inherits:
-
Object
- Object
- Webgen::Language
- 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
-
#codes ⇒ Object
readonly
An array containing the language codes for the language.
-
#description ⇒ Object
readonly
The english description of the language.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
:nodoc:.
-
#code2chars ⇒ Object
The two letter code.
-
#code3chars ⇒ Object
The three letter code.
-
#code3chars_alternative ⇒ Object
The alternative three letter code.
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(codes, description) ⇒ Language
constructor
Create a new language.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
(also: #to_str)
The textual representation of the language.
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
#codes ⇒ Object (readonly)
An array containing the language codes for the language.
12 13 14 |
# File 'lib/webgen/languages.rb', line 12 def codes @codes end |
#description ⇒ Object (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 |
#code2chars ⇒ Object
The two letter code.
26 27 28 |
# File 'lib/webgen/languages.rb', line 26 def code2chars @codes[2] end |
#code3chars ⇒ Object
The three letter code.
31 32 33 |
# File 'lib/webgen/languages.rb', line 31 def code3chars @codes[0] end |
#code3chars_alternative ⇒ Object
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:
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 |
#hash ⇒ Object
:nodoc:
60 61 62 |
# File 'lib/webgen/languages.rb', line 60 def hash #:nodoc: self.to_s.hash end |
#inspect ⇒ Object
:nodoc:
47 48 49 |
# File 'lib/webgen/languages.rb', line 47 def inspect #:nodoc: "#<Language codes=#{codes.inspect} description=#{description.inspect}>" end |
#to_s ⇒ Object 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 |