Created
March 17, 2016 18:02
-
-
Save theHamdiz/fc18b28392e6b0bb0268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Info | |
class << self | |
def method_missing(name, *args, &block) | |
case name | |
when /^get_(.*)/ | |
send($1, *args, &block) | |
else | |
super | |
end | |
end | |
end | |
def self.category_by id | |
begin | |
cat_id = get('drug_category').keep_if { |c| c[0] == id }.flatten[1] | |
categories = get('category') | |
cat = categories.select { |c| c[0] == cat_id } | |
parent_id = cat.flatten[1] | |
parent_cat = categories.select { |c| c[0] == parent_id } | |
parent_cat.flatten[2].empty? ? "#{cat.flatten[2]}" : "#{cat.flatten[2]} (#{parent_cat.flatten[2]})" | |
rescue => err | |
puts err | |
end | |
end | |
def self.company_by id | |
get('companies').keep_if { |c| c[0] == id }.flatten[1] | |
end | |
def self.active_ingredients id | |
ais = get('drug_ai') | |
active_ingredient = ais.select { |a| a[1] == id } | |
active_ingredient.each_with_object([]) do |ac, ing| | |
concentration = ac[2] | |
name = get('ai').select { |n| n[0] == ac[0] }.flatten | |
unit = get('drug_ai_unit').select { |u| u[0] == ac[3] }.flatten | |
ing << "#{name[1].capitalize} #{concentration} #{unit[1].downcase}" | |
end | |
end | |
def self.form id | |
get('form').select { |f| f[0] == id}.flatten[1] | |
end | |
end | |
def get file | |
file_name = file =~ /\.csv/ ? file : file + '.csv' | |
contents = CSV.read(file_name, col_sep: '|') | |
contents.shift | |
contents | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment