class BehindTheName::Usages

Public Class Methods

from(filename) click to toggle source
# 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
new(yml) click to toggle source
# File lib/behind_the_name/usages.rb, line 8
def initialize(yml)
  @data = yml
  generate_indices!
end

Public Instance Methods

include?(key) click to toggle source
# File lib/behind_the_name/usages.rb, line 23
def include?(key)
  @by_code.include?(key) || @by_full.include?(key)
end
normalize(usage) click to toggle source
# 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

Private Instance Methods

generate_indices!() click to toggle source
# File lib/behind_the_name/usages.rb, line 13
        def generate_indices!
  @by_code = @data.map { |datum| datum[:code].to_sym }
  @by_full = @data.group_by { |datum| datum[:full] }
end