Class: BehindTheName::Usages

Inherits:
Object
  • Object
show all
Defined in:
lib/behind_the_name/usages.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yml) ⇒ Usages

Returns a new instance of Usages.



8
9
10
11
# File 'lib/behind_the_name/usages.rb', line 8

def initialize(yml)
  @data = yml
  generate_indices!
end

Class Method Details

.from(filename) ⇒ Object



3
4
5
6
# File 'lib/behind_the_name/usages.rb', line 3

def self.from(filename)
  require 'yaml'
  (@usages ||= {})[filename] ||= new(YAML.load_file(File.join(__dir__, "#{filename}.yml")))
end

Instance Method Details

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/behind_the_name/usages.rb', line 23

def include?(key)
  @by_code.include?(key) || @by_full.include?(key)
end

#normalize(usage) ⇒ Object



18
19
20
21
# File 'lib/behind_the_name/usages.rb', line 18

def normalize(usage)
  return usage.to_sym if @by_code.include?(usage.to_sym)
  @by_full.fetch(usage).first.fetch(:code).to_sym
end