lib/csi.rb in csi-0.1.0 vs lib/csi.rb in csi-0.2.0
- old
+ new
@@ -1,17 +1,36 @@
+require 'toml'
+
class CSI
+
+ CURRENT_SIC_YEAR = 2000 # last accurate data set for SIC codes
+ CURRENT_NAICS_YEAR = 2012 # last accurate data set for NAICS codes
+
+ # Lookup the SIC code.
+ #
+ # Returns a String value of the SIC classification, or nil if not found.
def self.lookup_sic(code)
- return if code.nil?
+ lookup_code("sic", CURRENT_SIC_YEAR, code)
end
+ # Lookup the NAICS code.
+ #
+ # Returns a String value of the NAICS classification, or nil if not found.
def self.lookup_naics(code)
- return nil if code.nil?
+ lookup_code("naics", CURRENT_NAICS_YEAR, code)
+ end
+ private
+
+ # Lookup the classification based on the type, year, and code.
+ #
+ # Returns a String value for the resquested classification, or nil if not
+ # found.
+ def self.lookup_code(type, year, code)
+ raise TypeError, 'Integer required' unless code.is_a? Integer
+
begin
- file = File.open("#{File.expand_path(__FILE__+'/..')}/data/naics/2012/#{code}", "rb")
- contents = file.read
- contents.strip!
- return contents
+ TOML.load_file("#{File.expand_path(__FILE__+'/..')}/data/#{type}/#{year}/#{code.to_i}.toml")["name"]
rescue
return nil
end
end
end
\ No newline at end of file