Class: Bipm::Data::Importer::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/bipm/data/importer/language.rb

Overview

First-class language value object. English and French are equal citizens — neither is the canonical form, neither is a translation of the other. Both directions of any linguistic operation must be expressible through this type without one being the "default".

Constant Summary collapse

EN =
new(:en)
FR =
new(:fr)
ALL =
[EN, FR].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Language

Returns a new instance of Language.



13
14
15
# File 'lib/bipm/data/importer/language.rb', line 13

def initialize(code)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



11
12
13
# File 'lib/bipm/data/importer/language.rb', line 11

def code
  @code
end

Class Method Details

.allObject



27
28
29
# File 'lib/bipm/data/importer/language.rb', line 27

def self.all
  ALL
end

.find(name) ⇒ Object



21
22
23
24
25
# File 'lib/bipm/data/importer/language.rb', line 21

def self.find(name)
  sym = name.to_sym
  ALL.find { |l| l.code == sym } ||
    raise(ArgumentError, "unknown language: #{name.inspect} (supported: #{ALL.map(&:to_s).inspect})")
end

Instance Method Details

#directory_suffixObject



47
48
49
50
51
52
53
# File 'lib/bipm/data/importer/language.rb', line 47

def directory_suffix
  case @code
  when :en then "-en"
  when :fr then "-fr"
  else raise(ArgumentError, "no directory suffix for #{@code}")
  end
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


55
56
57
# File 'lib/bipm/data/importer/language.rb', line 55

def eql?(other)
  other.is_a?(Language) && @code == other.code
end

#hashObject



60
61
62
# File 'lib/bipm/data/importer/language.rb', line 60

def hash
  @code.hash
end

#suffixObject



39
40
41
42
43
44
45
# File 'lib/bipm/data/importer/language.rb', line 39

def suffix
  case @code
  when :en then ""
  when :fr then "-fr"
  else raise(ArgumentError, "no suffix defined for #{@code}")
  end
end

#to_sObject



31
32
33
# File 'lib/bipm/data/importer/language.rb', line 31

def to_s
  @code.to_s
end

#to_symObject



35
36
37
# File 'lib/bipm/data/importer/language.rb', line 35

def to_sym
  @code
end