Sha256: 79c6ddf0a57a55a0eb1079e9f20d068207eff2a2f4055100e8746005ad875392

Contents?: true

Size: 450 Bytes

Versions: 5

Compression:

Stored size: 450 Bytes

Contents

module ISO
  class Tag
    attr_accessor :language, :region

    def initialize(code)
      @code     = code
      @language = Language.identify(code)
      @region   = Region.identify(code) || UN::Region.identify(code)
    end

    def codes
      subtags.map(&:code)
    end

    def subtags
      [language, region].compact
    end

    def valid?
      return false if @language.nil?
      @code.split('-').size == subtags.size
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iso-0.4.0 lib/iso/tag.rb
iso-0.3.0 lib/iso/tag.rb
iso-0.2.2 lib/iso/tag.rb
iso-0.2.1 lib/iso/tag.rb
iso-0.2.0 lib/iso/tag.rb