Class: Lang::Tag::Grandfathered

Inherits:
Composition show all
Includes:
Filtering, Lookup
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

Filtering::WILDCARD

Instance Method Summary collapse

Methods included from Filtering

#matched_by_basic_range?, #matched_by_extended_range?

Methods included from Lookup

#in?, #lookup_candidates

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.

Raises:

  • (TypeError)


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_langtagObject



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