Class: Harbor::Locale
- Inherits:
-
Object
- Object
- Harbor::Locale
- Defined in:
- lib/harbor/locale.rb
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
readonly
Returns the value of attribute abbreviation.
-
#culture_code ⇒ Object
readonly
Returns the value of attribute culture_code.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Class Method Summary collapse
- .[](culture_code) ⇒ Object
- .activate!(*culture_codes) ⇒ Object
- .active_locales ⇒ Object
- .default ⇒ Object
- .default_culture_code ⇒ Object
- .default_culture_code=(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(culture_code, abbreviation, description) ⇒ Locale
constructor
A new instance of Locale.
- #to_s ⇒ Object
Constructor Details
#initialize(culture_code, abbreviation, description) ⇒ Locale
Returns a new instance of Locale.
40 41 42 43 44 |
# File 'lib/harbor/locale.rb', line 40 def initialize(culture_code, abbreviation, description) @culture_code = culture_code @abbreviation = abbreviation @description = description end |
Instance Attribute Details
#abbreviation ⇒ Object (readonly)
Returns the value of attribute abbreviation.
38 39 40 |
# File 'lib/harbor/locale.rb', line 38 def abbreviation @abbreviation end |
#culture_code ⇒ Object (readonly)
Returns the value of attribute culture_code.
38 39 40 |
# File 'lib/harbor/locale.rb', line 38 def culture_code @culture_code end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
38 39 40 |
# File 'lib/harbor/locale.rb', line 38 def description @description end |
Class Method Details
.[](culture_code) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/harbor/locale.rb', line 4 def self.[](culture_code) unless @locales @locales = {} ::File.read(Pathname(__FILE__).dirname + "locales.txt").split("\n").each do |line| next if line =~ /^\s*(\#.*)?$/ values = line.split(/\|/).map { |value| value.strip } @locales[values[1]] = Locale.new(values[1], values[0], values[2]) end end @locales[culture_code] end |
.activate!(*culture_codes) ⇒ Object
22 23 24 |
# File 'lib/harbor/locale.rb', line 22 def self.activate!(*culture_codes) @active_locales = culture_codes.map { |culture_code| self[culture_code] } end |
.active_locales ⇒ Object
18 19 20 |
# File 'lib/harbor/locale.rb', line 18 def self.active_locales @active_locales ||= [] end |
.default ⇒ Object
26 27 28 |
# File 'lib/harbor/locale.rb', line 26 def self.default @default ||= self[default_culture_code] end |
.default_culture_code ⇒ Object
30 31 32 |
# File 'lib/harbor/locale.rb', line 30 def self.default_culture_code @default_culture_code ||= "en-US" end |
.default_culture_code=(value) ⇒ Object
34 35 36 |
# File 'lib/harbor/locale.rb', line 34 def self.default_culture_code=(value) @default_culture_code = value end |
Instance Method Details
#to_s ⇒ Object
46 47 48 |
# File 'lib/harbor/locale.rb', line 46 def to_s @description end |