Sha256: 04024f9a470263949e8ee6bfd80d2c64b9b360160bb751ff7376c680297f00d3

Contents?: true

Size: 617 Bytes

Versions: 9

Compression:

Stored size: 617 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2015-2022, by Samuel Williams.

module Utopia
	# A structured representation of locale based on RFC3066.
	Locale = Struct.new(:language, :country, :variant) do
		def to_s
			to_a.compact.join('-')
		end
		
		def self.dump(instance)
			if instance
				instance.to_s
			end
		end
		
		def self.load(instance)
			if instance.is_a? String
				self.new(*instance.split('-', 3))
			elsif instance.is_a? Array
				return self.new(*instance)
			elsif instance.is_a? self
				return instance.frozen? ? instance : instance.dup
			end
		end
	end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
utopia-2.25.0 lib/utopia/locale.rb
utopia-2.24.4 lib/utopia/locale.rb
utopia-2.24.3 lib/utopia/locale.rb
utopia-2.24.1 lib/utopia/locale.rb
utopia-2.23.0 lib/utopia/locale.rb
utopia-2.22.2 lib/utopia/locale.rb
utopia-2.22.1 lib/utopia/locale.rb
utopia-2.22.0 lib/utopia/locale.rb
utopia-2.21.0 lib/utopia/locale.rb