Skip to content

Instantly share code, notes, and snippets.

@rgalindo33
Created September 22, 2015 09:18
Show Gist options
  • Save rgalindo33/614fcc8be03a6e20b635 to your computer and use it in GitHub Desktop.
Save rgalindo33/614fcc8be03a6e20b635 to your computer and use it in GitHub Desktop.
require 'singleton'
module Xing
module Industries
class Mapping
include Singleton
JSON_PATH = '../../../../industries/mapping.json'
OLD_DEFAULT = 77
NEW_DEFAULT = 230_000
HIGHEST_OLD_ID = 200
attr_reader :mapping
def initialize
json = JSON.parse File.read(File.expand_path(JSON_PATH, __FILE__))
@mapping = {
old_to_new: json["old_to_new"],
new_to_old: json["new_to_old"]
}
end
def self.to_new_format(id:)
instance.to_new_format(id: id)
end
def self.to_old_format(id:)
instance.to_old_format(id: id)
end
def map(id:)
warn "[DEPRECATION] `#map` is deprecated. Please use one of the new methods `to_new_format` and `to_old_format` instead."
if id < HIGHEST_OLD_ID
mapping[:old_to_new].fetch(id.to_s, NEW_DEFAULT)
else
mapping[:new_to_old].fetch(id.to_s, OLD_DEFAULT)
end
end
def to_new_format(id:)
return unless id
return id if id > HIGHEST_OLD_ID
mapping[:old_to_new].fetch(id.to_s, NEW_DEFAULT)
end
def to_old_format(id:)
return unless id
return id if id < HIGHEST_OLD_ID
mapping[:new_to_old].fetch(id.to_s, OLD_DEFAULT)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment