Class: Locale Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Representation of a system locale.
Used to compare the system language and languages defined using the cask language
stanza.
Defined Under Namespace
Classes: ParserError
Instance Attribute Summary collapse
- #language ⇒ String? readonly private
- #region ⇒ String? readonly private
- #script ⇒ String? readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #detect(locale_groups) ⇒ Enumerable<String, Locale>? private
- #include?(other) ⇒ Boolean private
- #initialize(language, script, region) ⇒ void constructor private
Constructor Details
#initialize(language, script, region) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'locale.rb', line 69 def initialize(language, script, region) raise ArgumentError, "#{self.class} cannot be empty" if language.nil? && region.nil? && script.nil? unless language.nil? regex = LANGUAGE_REGEX raise ParserError, "'language' does not match #{regex}" unless language.match?(regex) @language = T.let(language, T.nilable(String)) end unless script.nil? regex = SCRIPT_REGEX raise ParserError, "'script' does not match #{regex}" unless script.match?(regex) @script = T.let(script, T.nilable(String)) end return if region.nil? regex = REGION_REGEX raise ParserError, "'region' does not match #{regex}" unless region.match?(regex) @region = T.let(region, T.nilable(String)) end |
Instance Attribute Details
#language ⇒ String? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
60 61 62 |
# File 'locale.rb', line 60 def language @language end |
#region ⇒ String? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
66 67 68 |
# File 'locale.rb', line 66 def region @region end |
#script ⇒ String? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
63 64 65 |
# File 'locale.rb', line 63 def script @script end |
Class Method Details
.parse(string) ⇒ T.attached_class
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
28 29 30 31 32 33 34 |
# File 'locale.rb', line 28 def self.parse(string) if (locale = try_parse(string)) return locale end raise ParserError, "'#{string}' cannot be parsed to a #{self}" end |
.try_parse(string) ⇒ T.attached_class?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'locale.rb', line 37 def self.try_parse(string) return if string.blank? scanner = StringScanner.new(string) if (language = scanner.scan(LANGUAGE_REGEX)) sep = scanner.scan("-") return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?) end if (script = scanner.scan(SCRIPT_REGEX)) sep = scanner.scan("-") return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?) end region = scanner.scan(REGION_REGEX) return unless scanner.eos? new(language, script, region) end |
Instance Method Details
#detect(locale_groups) ⇒ Enumerable<String, Locale>?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
128 129 130 131 |
# File 'locale.rb', line 128 def detect(locale_groups) locale_groups.find { |locales| locales.any? { |locale| eql?(locale) } } || locale_groups.find { |locales| locales.any? { |locale| include?(locale) } } end |
#include?(other) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'locale.rb', line 95 def include?(other) unless other.is_a?(self.class) other = self.class.try_parse(other) return false if other.nil? end [:language, :script, :region].all? do |var| next true if other.public_send(var).nil? public_send(var) == other.public_send(var) end end |