Class: BCP47::Subtag::Language

Inherits:
Base
  • Object
show all
Defined in:
lib/bcp47/subtag/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 Base

#code, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, codes, default, find, #full_name

Constructor Details

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

Returns a new instance of Language.



10
11
12
13
14
# File 'lib/bcp47/subtag/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/subtag/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/subtag/language.rb', line 8

def plural_rule_names
  @plural_rule_names
end

Class Method Details

.identify(full_code) ⇒ Object



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

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