eulim 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ae4a069d424238d03ee05cdf5261aecc11c4c64
4
- data.tar.gz: 5ec6e25efaab183bd4d7cb2a9622d6f691b9004c
3
+ metadata.gz: 76954b537581b84d1e43fe48f92e5a471786cefc
4
+ data.tar.gz: 3d999849b4a639f64de0235fb888551057e469cd
5
5
  SHA512:
6
- metadata.gz: 09d19cc17e2be7ab42ae9e29924f241dc286caae6496bc7b09a71db65a7ba8d05915677f60603c6bbfab5b9822363ef23a80cdf0e43dfba2038ecfe896d4d843
7
- data.tar.gz: 7c655642b401042d157b99e4a6ea904eada04f2469bfd7a236f4642ff405bbeb37b7f29e2253719825013d93f66d7215674e2a3a4ebabd7ebb36e0186ff83f38
6
+ metadata.gz: 05d84bcf06f0173a0876bcb64434687d3e55d2f263fc3c322f45069f44b3e8baca011b31b37dbe14ed4ee403f693e1cfdef4dcd2bf29c7b26f3cee1652240264
7
+ data.tar.gz: 0f5aa27bab25f3a98288d53152e9a003857e10d3b15a3bb5cb2ad5028119fefd7f9ecf11558e60ea6fffef009567feb8e52040a51bee4ac93cd0b3678ca73850
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
 
32
32
  #### Element
33
33
 
34
- * H, He, Li, Be, B, C, N, O, F, Ne, Na, Mg, Al, Si, P, S, Cl, Ar, K , Ca, Sc, Ti, V, Cr, Mn, Fe, Co, Ni
34
+ * H, He, Li, Be, B, C, N, O, F, Ne, Na, Mg, Al, Si, P, S, Cl, Ar, K , Ca, Sc, Ti, V, Cr, Mn, Fe, Co, Ni, Cu, Zn, Ga, Ge, As, Se, Br, Kr, Rb, Sr, Y, Zr, Nb, Mo, Tc, Ru, Rh, Pd, Ag, Cd, In, Sn, Sb, Te, I, Xe, Cs, Ba, La, Ce, Pr, Nd, Pm, Sm, Eu, Gd, Tb, Dy, Ho, Er, Tm, Yb, Lu, Hf, Ta, W, Re, Os, Ir, Pt, Au, Hg, Tl, Pb, Bi, Po, At, Rn, Fr, Ra, Ac, Th, Pa, U, Np, Pu, Am, Cm, Bk, Cf, Es, Fm, Md, No, Lr, Rf, Db, Sg, Bh, Hs, Mt,
35
35
  * attributes: symbol, name, atomic_number, atomic_mass
36
36
  * methods: get_by_* (* can be any of the attributes)
37
37
 
@@ -41,19 +41,19 @@ Or install it yourself as:
41
41
  * methods: new(compound formula)
42
42
 
43
43
  ## Usage
44
+ ```ruby
45
+ $ Eulim::Chemistry::Element.get_by_symbol "H"
46
+ => #<Eulim::Chemistry::Element: @symbol="H", @name="Hydrogen", @atomic_number=1, @atomic_mass=1.0079>
44
47
 
45
- $ Eulim::Chemistry::Element.get_by_symbol "H"
46
- => #<Eulim::Chemistry::Element: @symbol="H", @name="Hydrogen", @atomic_number=1, @atomic_mass=1.0079>
47
-
48
- $ Eulim::Chemistry::Element.get_by_atomic_number 12
49
- => #<Eulim::Chemistry::Element: @symbol="Mg", @name="Magnesium", @atomic_number=12, @atomic_mass=24.305>
48
+ $ Eulim::Chemistry::Element.get_by_atomic_number 12
49
+ => #<Eulim::Chemistry::Element: @symbol="Mg", @name="Magnesium", @atomic_number=12, @atomic_mass=24.305>
50
50
 
51
- $ Eulim::Chemistry::Element.get_by_name "helium" # or "Helium"
52
- => #<Eulim::Chemistry::Element: @symbol="He", @name="Helium", @atomic_number=2, @atomic_mass=4.002602>
51
+ $ Eulim::Chemistry::Element.get_by_name "helium" # or "Helium"
52
+ => #<Eulim::Chemistry::Element: @symbol="He", @name="Helium", @atomic_number=2, @atomic_mass=4.002602>
53
53
 
54
- $ Eulim::Chemistry::Compound.new("CaCO3")
55
- => #<Eulim::Chemistry::Compound: @formula="CaCO3", @constituents=[{:element=>#<Eulim::Chemistry::Element: @symbol="Ca", @name="Calcium", @atomic_number=20, @atomic_mass=40.078>, :atom_count=>1}, {:element=>#<Eulim::Chemistry::Element: @symbol="C", @name="Carbon", @atomic_number=6, @atomic_mass=12.0107>, :atom_count=>1}, {:element=>#<Eulim::Chemistry::Element: @symbol="O", @name="Oxygen", @atomic_number=8, @atomic_mass=15.9996>, :atom_count=>3}], @molecular_mass=100.0875>
56
-
54
+ $ Eulim::Chemistry::Compound.new("CaCO3")
55
+ => #<Eulim::Chemistry::Compound: @formula="CaCO3", @constituents=[{:element=>#<Eulim::Chemistry::Element: @symbol="Ca", @name="Calcium", @atomic_number=20, @atomic_mass=40.078>, :atom_count=>1}, {:element=>#<Eulim::Chemistry::Element: @symbol="C", @name="Carbon", @atomic_number=6, @atomic_mass=12.0107>, :atom_count=>1}, {:element=>#<Eulim::Chemistry::Element: @symbol="O", @name="Oxygen", @atomic_number=8, @atomic_mass=15.9996>, :atom_count=>3}], @molecular_mass=100.0875>
56
+ ```
57
57
  ## Development
58
58
 
59
59
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "eulim"
3
+ require 'bundler/setup'
4
+ require 'eulim'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/eulim.gemspec CHANGED
@@ -1,38 +1,43 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'eulim/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "eulim"
8
+ spec.name = 'eulim'
8
9
  spec.version = Eulim::VERSION
9
- spec.authors = ["Syed Fazil Basheer"]
10
- spec.email = ["fazil.basheer@quester.xyz"]
10
+ spec.authors = ['Syed Fazil Basheer']
11
+ spec.email = ['fazil.basheer@quester.xyz']
11
12
 
12
- spec.summary = %q{A gem for scientific data.}
13
- spec.description = %q{A gem for scientific data.}
14
- spec.homepage = "https://github.com/syedfazilbasheer-quester/eulim-gem"
15
- spec.license = "MIT"
13
+ spec.summary = 'A gem for scientific data.'
14
+ spec.description = 'A gem for scientific data.'
15
+ spec.homepage = 'https://github.com/syedfazilbasheer-quester/eulim-gem'
16
+ spec.license = 'MIT'
16
17
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # Prevent pushing this gem to RubyGems.org.
19
+ # To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host
21
+ # or delete this section to allow pushing to any host.
19
22
  # if spec.respond_to?(:metadata)
20
- # spec.metadata['allowed_push_host'] = "https://github.com/syedfazilbasheer-quester/eulim-gem"
23
+ # spec.metadata['allowed_push_host'] =
24
+ # 'https://github.com/syedfazilbasheer-quester/eulim-gem'
21
25
  # else
22
- # raise "RubyGems 2.0 or newer is required to protect against " \
23
- # "public gem pushes."
26
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ # 'public gem pushes.'
24
28
  # end
25
29
 
26
30
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
31
  f.match(%r{^(test|spec|features)/})
28
32
  end
29
- spec.bindir = "exe"
33
+ spec.bindir = 'exe'
30
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
35
+ spec.require_paths = ['lib']
32
36
 
33
- spec.add_development_dependency "bundler", "~> 1.14"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency 'bundler', '~> 1.14'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'rubocop'
36
41
 
37
- spec.add_dependency "require_all", "~> 1.4.0"
42
+ spec.add_dependency 'require_all', '~> 1.4.0'
38
43
  end
data/lib/eulim.rb CHANGED
@@ -2,6 +2,7 @@ require 'require_all'
2
2
 
3
3
  require_all '../eulim/lib'
4
4
 
5
+ # Root module. Everything in the gem goes inside this
5
6
  module Eulim
6
7
  # Your code goes here...
7
8
  end
@@ -1,2 +1,6 @@
1
- module Chemistry
2
- end
1
+ module Eulim
2
+ # This module will contain all chemistry related info
3
+ # Ex: Elements, Compounds, Reactions, etc
4
+ module Chemistry
5
+ end
6
+ end
@@ -1,53 +1,59 @@
1
- module Eulim::Chemistry
2
- class Compound
1
+ module Eulim
2
+ module Chemistry
3
+ # This class has functionality for compounds
4
+ # Ex: constituent elements, molecular mass, etc
5
+ class Compound
6
+ COMPOUND_REGEXP =
7
+ /[A-Z][a-z]{0,2}\d*|\((?:[^()]*(?:\(.*\))?[^()]*)+\)\d*/
3
8
 
4
- VALID_COMPOUND_REGEXP = /[A-Z][a-z]{0,2}\d*|\((?:[^()]*(?:\(.*\))?[^()]*)+\)\d*/
9
+ attr_accessor :molecular_mass, :constituents, :formula
5
10
 
6
- attr_accessor :molecular_mass, :constituents, :formula
7
-
8
- def initialize(arg)
9
- @formula = arg
10
- @constituents = get_constituents
11
- @molecular_mass = get_molecular_mass
12
- end
11
+ def initialize(arg)
12
+ @formula = arg
13
+ @constituents = constituents
14
+ @molecular_mass = molecular_mass
15
+ end
13
16
 
14
- private
15
- def get_molecular_mass
16
- mass = 0
17
- @constituents.each do |constituent|
18
- mass += constituent[:element].atomic_mass * constituent[:atom_count]
19
- end
20
- mass
21
- end
17
+ private
22
18
 
23
- def get_constituents
24
- constituents = []
25
- get_constituent_atoms.each do |symbol, count|
26
- constituents << {element: Element.get_by_symbol(symbol), atom_count: count}
27
- end
28
- constituents
29
- end
19
+ def molecular_mass
20
+ mass = 0
21
+ @constituents.each do |const|
22
+ mass += const[:element].atomic_mass * const[:atom_count]
23
+ end
24
+ mass
25
+ end
30
26
 
31
- def get_constituent_atoms formula=@formula, result={}
32
- constituents = formula.scan VALID_COMPOUND_REGEXP
33
- constituents.each do |constituent|
34
- multipler = get_multipler constituent
35
- if constituent[0] != '(' && multipler == 0
36
- result[constituent] = result[constituent] ? result[constituent] + 1 : 1
37
- else
38
- (multipler == 0 ? 1 : multipler).times do
39
- sub_constituents = constituent.match(/^\(?(.*?)\)?($|\d*$)/).to_a
40
- idx = constituent == sub_constituents.first ? 1 : 0
41
- get_constituent_atoms sub_constituents[idx], result
42
- end
43
- end
44
- end
45
- result
46
- end
27
+ def constituents
28
+ constituents = []
29
+ get_const_atoms.each do |symbol, count|
30
+ constituents << {
31
+ element: Element.get_by_symbol(symbol),
32
+ atom_count: count
33
+ }
34
+ end
35
+ constituents
36
+ end
47
37
 
48
- def get_multipler constituent
49
- multipler = constituent.match(/\d*$/).to_a.first.to_i
50
- end
38
+ def get_const_atoms(formula = @formula, r = {})
39
+ formula.scan(COMPOUND_REGEXP).each do |const|
40
+ multipler = get_multipler const
41
+ if const[0] != '(' && multipler.zero?
42
+ r[const] = r[const] ? r[const] + 1 : 1
43
+ else
44
+ (multipler.zero? ? 1 : multipler).times do
45
+ sub_const = const.match(/^\(?(.*?)\)?($|\d*$)/).to_a
46
+ get_const_atoms sub_const[const == sub_const.first ? 1 : 0], r
47
+ end
48
+ end
49
+ end
50
+ r
51
+ end
51
52
 
52
- end
53
+ def get_multipler(const)
54
+ multipler = const.match(/\d*$/).to_a.first.to_i
55
+ multipler
56
+ end
57
+ end
58
+ end
53
59
  end
@@ -1,75 +1,265 @@
1
- module Eulim::Chemistry
2
- class Element
1
+ module Eulim
2
+ module Chemistry
3
+ # This class has functionality for elements
4
+ # Ex: symbol, atomic mass, atomic number
5
+ class Element
6
+ VALID_SYMBOL_REGEXP = /[A-Z][a-z]{0,2}/
7
+ VALID_NAME_REGEXP = /[A-Z][a-z]+/
3
8
 
4
- VALID_SYMBOL_REGEXP = /[A-Z][a-z]{0,2}/
5
- VALID_NAME_REGEXP = /[A-Z][a-z]+/
9
+ attr_accessor :atomic_mass, :symbol, :name, :atomic_number
6
10
 
7
- attr_accessor :atomic_mass, :symbol, :name, :atomic_number
11
+ @@attrs = %w[symbol name atomic_number atomic_mass]
8
12
 
9
- @@attributes = ['symbol', 'name', 'atomic_number', 'atomic_mass']
10
- @@elements = [
11
- { symbol:'H', name: 'Hydrogen', atomic_number: 1, atomic_mass: 1.0079 },
12
- { symbol:'He', name: 'Helium', atomic_number: 2, atomic_mass: 4.002602 },
13
- { symbol:'Li', name: 'Lithium', atomic_number: 3, atomic_mass: 6.941 },
14
- { symbol:'Be', name: 'Beryllium', atomic_number: 4, atomic_mass: 9.012182 },
15
- { symbol:'B', name: 'Boron', atomic_number: 5, atomic_mass: 10.811 },
16
- { symbol:'C', name: 'Carbon', atomic_number: 6, atomic_mass: 12.0107 },
17
- { symbol:'N', name: 'Nitrogen', atomic_number: 7, atomic_mass: 14.0067 },
18
- { symbol:'O', name: 'Oxygen', atomic_number: 8, atomic_mass: 15.9996 },
19
- { symbol:'F', name: 'Fluorine', atomic_number: 9, atomic_mass: 18.9984 },
20
- { symbol:'Ne', name: 'Neon', atomic_number: 10, atomic_mass: 20.1797 },
21
- { symbol:'Na', name: 'Sodium', atomic_number: 11, atomic_mass: 22.9897 },
22
- { symbol:'Mg', name: 'Magnesium', atomic_number: 12, atomic_mass: 24.305 },
23
- { symbol:'Al', name: 'Aluminium', atomic_number: 13, atomic_mass: 26.9815 },
24
- { symbol:'Si', name: 'Silicon', atomic_number: 14, atomic_mass: 28.0855 },
25
- { symbol:'P', name: 'Phosphorus', atomic_number: 15, atomic_mass: 30.9738 },
26
- { symbol:'S', name: 'Sulfur', atomic_number: 16, atomic_mass: 32.065 },
27
- { symbol:'Cl', name: 'Chlorine', atomic_number: 17, atomic_mass: 35.453 },
28
- { symbol:'Ar', name: 'Argon', atomic_number: 18, atomic_mass: 39.948 },
29
- { symbol:'K', name: 'Potassium', atomic_number: 19, atomic_mass: 39.0983 },
30
- { symbol:'Ca', name: 'Calcium', atomic_number: 20, atomic_mass: 40.078 },
31
- { symbol:'Sc', name: 'Scandium', atomic_number: 21, atomic_mass: 44.9559 },
32
- { symbol:'Ti', name: 'Titanium', atomic_number: 22, atomic_mass: 47.867 },
33
- { symbol:'V', name: 'Vanadium', atomic_number: 23, atomic_mass: 50.9415 },
34
- { symbol:'Cr', name: 'Chromium', atomic_number: 24, atomic_mass: 51.9961 },
35
- { symbol:'Mn', name: 'Manganese', atomic_number: 25, atomic_mass: 54.938 },
36
- { symbol:'Fe', name: 'Iron', atomic_number: 26, atomic_mass: 55.845 },
37
- { symbol:'Co', name: 'Cobalt', atomic_number: 27, atomic_mass: 58.9332 },
38
- { symbol:'Ni', name: 'Nickel', atomic_number: 28, atomic_mass: 58.6934 }
39
- ]
13
+ def initialize(args)
14
+ return nil unless args
15
+ args.each do |k, v|
16
+ instance_variable_set("@#{k}", v) unless v.nil?
17
+ end
18
+ end
40
19
 
41
- private
42
- def self.method_missing m, *args
43
- if m.to_s.start_with?("get_by_")
44
- attribute = m.to_s.split("get_by_").last
45
- if @@attributes.include? attribute
46
- args[0] = attribute == 'name' ? args[0].capitalize : args[0]
47
- element_data = self.all.select { |element| element[attribute.to_sym] === args[0]}.first
48
- if element_data
49
- new(element_data)
50
- else
51
- raise "Element not found"
52
- end
53
- else
54
- raise NameError, "Element class does not have that attribute or method"
55
- end
56
- else
57
- super
58
- end
59
- end
20
+ # Data taken from 'www.science.co.il/elements/'
21
+ @@elements = [
22
+ { symbol: 'H', name: 'Hydrogen',
23
+ atomic_number: 1, atomic_mass: 1.0079 },
24
+ { symbol: 'He', name: 'Helium',
25
+ atomic_number: 2, atomic_mass: 4.002602 },
26
+ { symbol: 'Li', name: 'Lithium',
27
+ atomic_number: 3, atomic_mass: 6.941 },
28
+ { symbol: 'Be', name: 'Beryllium',
29
+ atomic_number: 4, atomic_mass: 9.012182 },
30
+ { symbol: 'B', name: 'Boron',
31
+ atomic_number: 5, atomic_mass: 10.811 },
32
+ { symbol: 'C', name: 'Carbon',
33
+ atomic_number: 6, atomic_mass: 12.0107 },
34
+ { symbol: 'N', name: 'Nitrogen',
35
+ atomic_number: 7, atomic_mass: 14.0067 },
36
+ { symbol: 'O', name: 'Oxygen',
37
+ atomic_number: 8, atomic_mass: 15.9996 },
38
+ { symbol: 'F', name: 'Fluorine',
39
+ atomic_number: 9, atomic_mass: 18.9984 },
40
+ { symbol: 'Ne', name: 'Neon',
41
+ atomic_number: 10, atomic_mass: 20.1797 },
42
+ { symbol: 'Na', name: 'Sodium',
43
+ atomic_number: 11, atomic_mass: 22.9897 },
44
+ { symbol: 'Mg', name: 'Magnesium',
45
+ atomic_number: 12, atomic_mass: 24.305 },
46
+ { symbol: 'Al', name: 'Aluminium',
47
+ atomic_number: 13, atomic_mass: 26.9815 },
48
+ { symbol: 'Si', name: 'Silicon',
49
+ atomic_number: 14, atomic_mass: 28.0855 },
50
+ { symbol: 'P', name: 'Phosphorus',
51
+ atomic_number: 15, atomic_mass: 30.9738 },
52
+ { symbol: 'S', name: 'Sulfur',
53
+ atomic_number: 16, atomic_mass: 32.065 },
54
+ { symbol: 'Cl', name: 'Chlorine',
55
+ atomic_number: 17, atomic_mass: 35.453 },
56
+ { symbol: 'Ar', name: 'Argon',
57
+ atomic_number: 18, atomic_mass: 39.948 },
58
+ { symbol: 'K', name: 'Potassium',
59
+ atomic_number: 19, atomic_mass: 39.0983 },
60
+ { symbol: 'Ca', name: 'Calcium',
61
+ atomic_number: 20, atomic_mass: 40.078 },
62
+ { symbol: 'Sc', name: 'Scandium',
63
+ atomic_number: 21, atomic_mass: 44.9559 },
64
+ { symbol: 'Ti', name: 'Titanium',
65
+ atomic_number: 22, atomic_mass: 47.867 },
66
+ { symbol: 'V', name: 'Vanadium',
67
+ atomic_number: 23, atomic_mass: 50.9415 },
68
+ { symbol: 'Cr', name: 'Chromium',
69
+ atomic_number: 24, atomic_mass: 51.9961 },
70
+ { symbol: 'Mn', name: 'Manganese',
71
+ atomic_number: 25, atomic_mass: 54.938 },
72
+ { symbol: 'Fe', name: 'Iron',
73
+ atomic_number: 26, atomic_mass: 55.845 },
74
+ { symbol: 'Co', name: 'Cobalt',
75
+ atomic_number: 27, atomic_mass: 58.9332 },
76
+ { symbol: 'Ni', name: 'Nickel',
77
+ atomic_number: 28, atomic_mass: 58.6934 },
78
+ { symbol: 'Cu', name: 'Copper',
79
+ atomic_number: 29, atomic_mass: 63.546 },
80
+ { symbol: 'Zn', name: 'Zinc',
81
+ atomic_number: 30, atomic_mass: 65.39 },
82
+ { symbol: 'Ga', name: 'Gallium',
83
+ atomic_number: 31, atomic_mass: 69.723 },
84
+ { symbol: 'Ge', name: 'Germanium',
85
+ atomic_number: 32, atomic_mass: 72.64 },
86
+ { symbol: 'As', name: 'Arsenic',
87
+ atomic_number: 33, atomic_mass: 74.9216 },
88
+ { symbol: 'Se', name: 'Selenium',
89
+ atomic_number: 34, atomic_mass: 78.96 },
90
+ { symbol: 'Br', name: 'Bromine',
91
+ atomic_number: 35, atomic_mass: 79.904 },
92
+ { symbol: 'Kr', name: 'Krypton',
93
+ atomic_number: 36, atomic_mass: 83.3 },
94
+ { symbol: 'Rb', name: 'Rubidium',
95
+ atomic_number: 37, atomic_mass: 85.4678 },
96
+ { symbol: 'Sr', name: 'Strontium',
97
+ atomic_number: 38, atomic_mass: 87.62 },
98
+ { symbol: 'Y', name: 'Yttrium',
99
+ atomic_number: 39, atomic_mass: 88.9059 },
100
+ { symbol: 'Zr', name: 'Zirconium',
101
+ atomic_number: 40, atomic_mass: 91.224 },
102
+ { symbol: 'Nb', name: 'Niobium',
103
+ atomic_number: 41, atomic_mass: 92.9064 },
104
+ { symbol: 'Mo', name: 'Molybdenum',
105
+ atomic_number: 42, atomic_mass: 95.94 },
106
+ { symbol: 'Tc', name: 'Technitium',
107
+ atomic_number: 43, atomic_mass: 98 },
108
+ { symbol: 'Ru', name: 'Ruthenium',
109
+ atomic_number: 44, atomic_mass: 101.07 },
110
+ { symbol: 'Rh', name: 'Rhodium',
111
+ atomic_number: 45, atomic_mass: 102.9055 },
112
+ { symbol: 'Pd', name: 'Palladium',
113
+ atomic_number: 46, atomic_mass: 106.42 },
114
+ { symbol: 'Ag', name: 'Silver',
115
+ atomic_number: 47, atomic_mass: 107.8682 },
116
+ { symbol: 'Cd', name: 'Cadmiuim',
117
+ atomic_number: 48, atomic_mass: 112.411 },
118
+ { symbol: 'In', name: 'Indium',
119
+ atomic_number: 49, atomic_mass: 114.818 },
120
+ { symbol: 'Sn', name: 'Tin',
121
+ atomic_number: 50, atomic_mass: 118.71 },
122
+ { symbol: 'Sb', name: 'Antimony',
123
+ atomic_number: 51, atomic_mass: 121.76 },
124
+ { symbol: 'Te', name: 'Tellurium',
125
+ atomic_number: 52, atomic_mass: 127.6 },
126
+ { symbol: 'I', name: 'Iodine',
127
+ atomic_number: 53, atomic_mass: 126.9045 },
128
+ { symbol: 'Xe', name: 'Xenon',
129
+ atomic_number: 54, atomic_mass: 131.293 },
130
+ { symbol: 'Cs', name: 'Cesium',
131
+ atomic_number: 55, atomic_mass: 132.9055 },
132
+ { symbol: 'Ba', name: 'Barium',
133
+ atomic_number: 56, atomic_mass: 137.327 },
134
+ { symbol: 'La', name: 'Lanthanum',
135
+ atomic_number: 57, atomic_mass: 138.9055 },
136
+ { symbol: 'Ce', name: 'Cerium',
137
+ atomic_number: 58, atomic_mass: 140.116 },
138
+ { symbol: 'Pr', name: 'Praseodymium',
139
+ atomic_number: 59, atomic_mass: 140.9077 },
140
+ { symbol: 'Nd', name: 'Neodymium',
141
+ atomic_number: 60, atomic_mass: 144.24 },
142
+ { symbol: 'Pm', name: 'Promethium',
143
+ atomic_number: 61, atomic_mass: 145 },
144
+ { symbol: 'Sm', name: 'Samarium',
145
+ atomic_number: 62, atomic_mass: 150.36 },
146
+ { symbol: 'Eu', name: 'Europium',
147
+ atomic_number: 63, atomic_mass: 151.964 },
148
+ { symbol: 'Gd', name: 'Gadolium',
149
+ atomic_number: 64, atomic_mass: 157.25 },
150
+ { symbol: 'Tb', name: 'Terbium',
151
+ atomic_number: 65, atomic_mass: 158.9253 },
152
+ { symbol: 'Dy', name: 'Dysprosium',
153
+ atomic_number: 66, atomic_mass: 162.5 },
154
+ { symbol: 'Ho', name: 'Holmium',
155
+ atomic_number: 67, atomic_mass: 164.9303 },
156
+ { symbol: 'Er', name: 'Erbium',
157
+ atomic_number: 68, atomic_mass: 167.259 },
158
+ { symbol: 'Tm', name: 'Thulium',
159
+ atomic_number: 69, atomic_mass: 168.9342 },
160
+ { symbol: 'Yb', name: 'Ytterbium',
161
+ atomic_number: 70, atomic_mass: 173.04 },
162
+ { symbol: 'Lu', name: 'Lutetium',
163
+ atomic_number: 71, atomic_mass: 174.967 },
164
+ { symbol: 'Hf', name: 'Hafnium',
165
+ atomic_number: 72, atomic_mass: 178.49 },
166
+ { symbol: 'Ta', name: 'Tantalum',
167
+ atomic_number: 73, atomic_mass: 180.9479 },
168
+ { symbol: 'W', name: 'Tungsten',
169
+ atomic_number: 74, atomic_mass: 183.84 },
170
+ { symbol: 'Re', name: 'Rhenium',
171
+ atomic_number: 75, atomic_mass: 186.207 },
172
+ { symbol: 'Os', name: 'Osmium',
173
+ atomic_number: 76, atomic_mass: 190.23 },
174
+ { symbol: 'Ir', name: 'Iridium',
175
+ atomic_number: 77, atomic_mass: 192.217 },
176
+ { symbol: 'Pt', name: 'Platinum',
177
+ atomic_number: 78, atomic_mass: 195.078 },
178
+ { symbol: 'Au', name: 'Gold',
179
+ atomic_number: 79, atomic_mass: 196.9665 },
180
+ { symbol: 'Hg', name: 'Mercury',
181
+ atomic_number: 80, atomic_mass: 200.59 },
182
+ { symbol: 'Tl', name: 'Thallium',
183
+ atomic_number: 81, atomic_mass: 204.3833 },
184
+ { symbol: 'Pb', name: 'Lead',
185
+ atomic_number: 82, atomic_mass: 207.2 },
186
+ { symbol: 'Bi', name: 'Bismuth',
187
+ atomic_number: 83, atomic_mass: 208.9804 },
188
+ { symbol: 'Po', name: 'Polonium',
189
+ atomic_number: 84, atomic_mass: 209 },
190
+ { symbol: 'At', name: 'Astatine',
191
+ atomic_number: 85, atomic_mass: 210 },
192
+ { symbol: 'Rn', name: 'Radon',
193
+ atomic_number: 86, atomic_mass: 222 },
194
+ { symbol: 'Fr', name: 'Francium',
195
+ atomic_number: 87, atomic_mass: 223 },
196
+ { symbol: 'Ra', name: 'Radium',
197
+ atomic_number: 88, atomic_mass: 226 },
198
+ { symbol: 'Ac', name: 'Actinium',
199
+ atomic_number: 89, atomic_mass: 227 },
200
+ { symbol: 'Th', name: 'Thorium',
201
+ atomic_number: 90, atomic_mass: 232.0381 },
202
+ { symbol: 'Pa', name: 'Protactinium',
203
+ atomic_number: 91, atomic_mass: 231.0359 },
204
+ { symbol: 'U', name: 'Uranium',
205
+ atomic_number: 92, atomic_mass: 238.0289 },
206
+ { symbol: 'Np', name: 'Neptunum',
207
+ atomic_number: 93, atomic_mass: 237 },
208
+ { symbol: 'Pu', name: 'Plutonium',
209
+ atomic_number: 94, atomic_mass: 244 },
210
+ { symbol: 'Am', name: 'Americium',
211
+ atomic_number: 95, atomic_mass: 243 },
212
+ { symbol: 'Cm', name: 'Curium',
213
+ atomic_number: 96, atomic_mass: 247 },
214
+ { symbol: 'Bk', name: 'Berkilium',
215
+ atomic_number: 97, atomic_mass: 247 },
216
+ { symbol: 'Cf', name: 'Californium',
217
+ atomic_number: 98, atomic_mass: 251 },
218
+ { symbol: 'Es', name: 'Einsteinium',
219
+ atomic_number: 99, atomic_mass: 252 },
220
+ { symbol: 'Fm', name: 'Fermium',
221
+ atomic_number: 100, atomic_mass: 257 },
222
+ { symbol: 'Md', name: 'Mendelevium',
223
+ atomic_number: 101, atomic_mass: 258 },
224
+ { symbol: 'No', name: 'Nobelium',
225
+ atomic_number: 102, atomic_mass: 259 },
226
+ { symbol: 'Lr', name: 'Lawrencium',
227
+ atomic_number: 103, atomic_mass: 262 },
228
+ { symbol: 'Rf', name: 'Rutherfordium',
229
+ atomic_number: 104, atomic_mass: 261 },
230
+ { symbol: 'Db', name: 'Dubnium',
231
+ atomic_number: 105, atomic_mass: 262 },
232
+ { symbol: 'Sg', name: 'Seaborgium',
233
+ atomic_number: 106, atomic_mass: 266 },
234
+ { symbol: 'Bh', name: 'Bohrium',
235
+ atomic_number: 107, atomic_mass: 264 },
236
+ { symbol: 'Hs', name: 'Hassium',
237
+ atomic_number: 108, atomic_mass: 277 },
238
+ { symbol: 'Mt', name: 'Meitnerium',
239
+ atomic_number: 109, atomic_mass: 268 }
240
+ ]
60
241
 
61
- def self.all
62
- @@elements
63
- end
242
+ private_class_method def self.method_missing(m, *args)
243
+ attribute = m.to_s.split('get_by_').last
244
+ valid_method? m, attribute
245
+ args[0] = attribute == 'name' ? args[0].capitalize : args[0]
246
+ element_data = get_element_by_attribute attribute, args[0]
247
+ raise 'Element not found' unless element_data
248
+ new(element_data)
249
+ end
64
250
 
65
- def initialize args
66
- if args
67
- args.each do |k,v|
68
- instance_variable_set("@#{k}", v) unless v.nil?
69
- end
70
- else
71
- nil
72
- end
73
- end
74
- end
75
- end
251
+ private_class_method def self.get_element_by_attribute(attribute, value)
252
+ @@elements.select do |element|
253
+ element[attribute.to_sym] == value
254
+ end.first
255
+ end
256
+
257
+ private_class_method def self.valid_method?(m, attribute)
258
+ super unless m.to_s.start_with?('get_by_')
259
+ raise(NameError, 'Invalid attribute') unless @@attrs.include? attribute
260
+ end
261
+
262
+ private_class_method :new
263
+ end
264
+ end
265
+ end
@@ -1,2 +1,6 @@
1
- module Structures
2
- end
1
+ module Eulim
2
+ # This module will contain all physical structures
3
+ # Ex: pipes, sheets, walls, bridges, etc
4
+ module Structures
5
+ end
6
+ end
@@ -1,12 +1,13 @@
1
1
  module Eulim
2
- module Structures
3
- class Pipe < Structure
4
- def initialize(*args)
5
- end
2
+ module Structures
3
+ # This is the class for Pipe
4
+ # It inherits from Structure
5
+ class Pipe < Structure
6
+ def initialize(*args) end
6
7
 
7
- def self.requirements
8
- "gimme radius, length, thickness, material..."
9
- end
10
- end
11
- end
12
- end
8
+ def self.requirements
9
+ 'gimme radius, length, thickness, material...'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,12 +1,12 @@
1
1
  module Eulim
2
- module Structures
3
- class Structure
4
- def initialize(*args)
5
- end
2
+ module Structures
3
+ # This is the base class for all structures
4
+ class Structure
5
+ def initialize(*args) end
6
6
 
7
- def self.requirements
8
- "gimme some stuff."
9
- end
10
- end
11
- end
12
- end
7
+ def self.requirements
8
+ 'gimme some stuff.'
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/eulim/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eulim
2
- VERSION = "0.0.7"
2
+ VERSION = '0.0.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eulim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Syed Fazil Basheer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: require_all
57
71
  requirement: !ruby/object:Gem::Requirement