Class: BCP47::Language

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

Constant Summary collapse

DEFINITIONS_FILE =
"#{File.dirname(__FILE__)}/../../data/iso-639-1.yml"
DEFAULT_PLURAL_RULE_NAMES =
%w(one other)
DEFAULT_DIRECTION =
'ltr'
DEFAULT_CODE =
'en'
PLURAL_RULE_NAMES =
%w(zero one two few many other)

Instance Attribute Summary collapse

Attributes inherited from Subtag

#code

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Subtag

#==, all, codes, default, find, #full_name, #name

Constructor Details

#initialize(code, options = {}) ⇒ Language

Returns a new instance of Language.



10
11
12
13
14
# File 'lib/bcp47/language.rb', line 10

def initialize(code, options={})
  @plural_rule_names = options[:plural_rule_names] || DEFAULT_PLURAL_RULE_NAMES
  @direction         = options[:direction]         || DEFAULT_DIRECTION
  super(code, options)
end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



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

def direction
  @direction
end

#plural_rule_namesObject (readonly)

Returns the value of attribute plural_rule_names.



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

def plural_rule_names
  @plural_rule_names
end

Class Method Details

.identify(full_code) ⇒ Object



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

def self.identify(full_code)
  segments = full_code.split('-')
  segments.first =~ /^([a-z]{2})$/ ? find($1) : nil
end