class ChemicalElements::PeriodicTable
Constants
- CHMICAL_FILE_PATH
Attributes
atomic_amount[RW]
atomic_num[RW]
name[RW]
symbol[RW]
Public Class Methods
all()
click to toggle source
# File lib/chemical_elements.rb, line 24 def self.all data.values.map { |value| build(value) } end
build(chemical_element)
click to toggle source
# File lib/chemical_elements.rb, line 13 def self.build(chemical_element) chemical = new chemical.name = chemical_element[:name] chemical.symbol = chemical_element[:symbol] chemical.atomic_num = chemical_element[:atomic_num] chemical.atomic_amount = chemical_element[:atomic_amount] chemical end
data()
click to toggle source
# File lib/chemical_elements.rb, line 8 def self.data filepath = File.join(File.dirname(__FILE__), CHMICAL_FILE_PATH) YAML.load_file(filepath) end
find(string)
click to toggle source
# File lib/chemical_elements.rb, line 28 def self.find(string) return if string.nil? chemical_element = find_chemcial_elements(:symbol, string) build(chemical_element) end
find_by(args)
click to toggle source
# File lib/chemical_elements.rb, line 35 def self.find_by(args) return if args.nil? chemical_element = find_chemcial_elements(args.keys[0], args.values[0]) build(chemical_element) end
find_chemcial_elements(key, value)
click to toggle source
# File lib/chemical_elements.rb, line 42 def self.find_chemcial_elements(key, value) case key when :name, :symbol data.values.map { |val| return val if val[key].casecmp(value).zero? } when :atomic_num, :atomic_amount data.values.map { |val| return val if val[key] == value } end end