File: tag.rb

package info (click to toggle)
ruby-iso 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 196 kB
  • sloc: ruby: 364; makefile: 4
file content (24 lines) | stat: -rw-r--r-- 450 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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