Class: Lang::Tag::Grandfathered
- Inherits:
-
Composition
- Object
- Composition
- Lang::Tag::Grandfathered
- Defined in:
- lib/lang/tag/grandfathered.rb,
lib/lang/tag/lookup.rb,
lib/lang/tag/filtering.rb
Overview
Handles grandfathered registrations.
Constant Summary
Constants included from Filtering
Instance Method Summary collapse
-
#initialize(thing) ⇒ Grandfathered
constructor
A new instance of Grandfathered.
- #to_langtag ⇒ Object
Methods included from Filtering
#matched_by_basic_range?, #matched_by_extended_range?
Methods included from Lookup
Methods inherited from Composition
#==, #===, #composition, #dup, #eql?, #hash, #inspect, #length, #nicecase, #nicecase!, #subtags_count, #to_a, #to_s
Constructor Details
#initialize(thing) ⇒ Grandfathered
Returns a new instance of Grandfathered.
15 16 17 18 19 20 21 22 |
# File 'lib/lang/tag/grandfathered.rb', line 15 def initialize(thing) raise TypeError, "Can't convert #{thing.class} into String" unless thing.respond_to?(:to_str) sequence = thing.to_str unless Lang::Tag.grandfathered?(sequence) raise ArgumentError, "#{sequence.inspect} is not a grandfathered language tag" end @sequence = sequence end |
Instance Method Details
#to_langtag ⇒ Object
24 25 26 27 28 29 |
# File 'lib/lang/tag/grandfathered.rb', line 24 def to_langtag unless preferred_value = GRANDFATHERED[@sequence.downcase] raise Error, "There is no preferred value for the grandfathered language tag #{@sequence.inspect}." end Tag::Langtag(preferred_value) end |