elementic 0.9.3 → 1.0
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 +4 -4
- data/Gemfile +4 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/elementic.gemspec +24 -0
- data/lib/elementic/element.rb +17 -0
- data/lib/elementic/periodic_table.rb +19 -0
- data/lib/elementic/version.rb +3 -0
- data/lib/elementic.rb +2 -205
- metadata +42 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b77362286d7f60f93abfc2367fcab71245abecb2
|
4
|
+
data.tar.gz: 8dc0a916bcebfdf7a9a1461db6f6c8cfaac0f404
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fc61cdc28f06d45648353eb3f046c5acf62d51d6602502799821993aaeb5126af317213c26150d1e9a14f0a3bd18796251b9cb2916ad93a0e18f67f19d1b153
|
7
|
+
data.tar.gz: 3b11cdc48e9e76c4ae1ea98b7f7606676dfce078413a4a20cb2db9690a92d2596d1518d226381a9ac74e73aca16e974005b49cf3c90b8bf2b260447c0e587684
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Elementic
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'elementic'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install elementic
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/elementic/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/elementic.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'elementic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'elementic'
|
8
|
+
spec.version = Elementic::VERSION
|
9
|
+
spec.authors = 'Josh'
|
10
|
+
spec.email = 'joshception@icloud.com'
|
11
|
+
spec.summary = 'Easy chemistry in Ruby'
|
12
|
+
spec.description = 'A usable hash (and some methods to boot) of
|
13
|
+
the Periodic table of elements'
|
14
|
+
spec.homepage = 'http://rubygems.org/gems/elementic'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Element Class
|
2
|
+
class Element
|
3
|
+
attr_accessor :name, :symbol, :ion_charges, :atomic_number, :atomic_mass,
|
4
|
+
:protons, :neutrons, :neutral
|
5
|
+
def initialize(info={})
|
6
|
+
@name = info[:name]
|
7
|
+
@symbol = info[:symbol]
|
8
|
+
@ion_charges = info[:ion_charges]
|
9
|
+
@atomic_number = info[:atomic_number]
|
10
|
+
@atomic_mass = info[:atomic_mass]
|
11
|
+
@protons = @atomic_number
|
12
|
+
@neutrons = @atomic_mass - @atomic_number
|
13
|
+
@neutral = true unless info[:neutral] == false
|
14
|
+
#worry about 'algorithm' for electrons later
|
15
|
+
#add weight of element
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'element'
|
2
|
+
$hydrogen = Element.new(
|
3
|
+
name:'Hydrogen', symbol:'H', ion_charges:[+1, -1],
|
4
|
+
atomic_number:1, atomic_mass:1.0
|
5
|
+
)
|
6
|
+
$helium = Element.new(
|
7
|
+
name: 'Helium', symbol:'He', ion_charges:[],
|
8
|
+
atomic_number:2, atomic_mass:4.0
|
9
|
+
)
|
10
|
+
|
11
|
+
$lithium = Element.new(
|
12
|
+
name: 'Lithium', symbol: 'Li', ion_charges:[+1],
|
13
|
+
atomic_number:3, atomic_mass:6.9
|
14
|
+
)
|
15
|
+
|
16
|
+
$beryllium = Element.new(
|
17
|
+
name: 'Beryllium', symbol: 'Be', ion_charges:[2+],
|
18
|
+
atomic_number:4, atomic_mass:9.0
|
19
|
+
)
|
data/lib/elementic.rb
CHANGED
@@ -1,205 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
NUMBER = '0.9.3'
|
4
|
-
end
|
5
|
-
|
6
|
-
$elements = {
|
7
|
-
'H' => 'Hydrogen',
|
8
|
-
'Li' => 'Lithium',
|
9
|
-
'He' => 'Helium',
|
10
|
-
'Be' => 'Beryliium',
|
11
|
-
'B' => 'Boron',
|
12
|
-
'C' => 'Carbon',
|
13
|
-
'N' => 'Nitrogen',
|
14
|
-
'O' => 'Oxygen',
|
15
|
-
'F' => 'Fluorine',
|
16
|
-
'Ne' => 'Neon',
|
17
|
-
'Na' => 'Sodium',
|
18
|
-
'Mg' => 'Magnesium',
|
19
|
-
'Al' => 'Aluminum',
|
20
|
-
'Si' => 'Silicon',
|
21
|
-
'P' => 'Phosphorus',
|
22
|
-
'S' => 'Sulfur',
|
23
|
-
'Cl' => 'Chlorine',
|
24
|
-
'Ar' => 'Argon',
|
25
|
-
'K' => 'Potassium',
|
26
|
-
'Ca' => 'Calcium',
|
27
|
-
'Sc' => 'Scandium',
|
28
|
-
'Ti' => 'Titanium',
|
29
|
-
'V' => 'Vanadium',
|
30
|
-
'Cr' => 'Chromium',
|
31
|
-
'Mn' => 'Manganese',
|
32
|
-
'Fe' => 'Iron',
|
33
|
-
'Co' => 'Cobalt',
|
34
|
-
'Ni' => 'Nickel',
|
35
|
-
'Cu' => 'Copper',
|
36
|
-
'Zn' => 'Zinc',
|
37
|
-
'Ga' => 'Gallium',
|
38
|
-
'Ge' => 'Germanium',
|
39
|
-
'As' => 'Arsenic',
|
40
|
-
'Se' => 'Selenium',
|
41
|
-
'Br' => 'Bromine',
|
42
|
-
'Kr' => 'Krypton',
|
43
|
-
'Rb' => 'Rubidium',
|
44
|
-
'Sr' => 'Strontium',
|
45
|
-
'Y' => 'Yttrium',
|
46
|
-
'Zr' => 'Zirconium',
|
47
|
-
'Nb' => 'Niobium',
|
48
|
-
'Mo' => 'Molybdenum',
|
49
|
-
'Tc' => 'Technetium',
|
50
|
-
'Ru' => 'Ruthenium',
|
51
|
-
'Rh' => 'Rhodium',
|
52
|
-
'Pd' => 'Palladium',
|
53
|
-
'Ag' => 'Silver',
|
54
|
-
'Cd' => 'Cadmium',
|
55
|
-
'In' => 'Indium',
|
56
|
-
'Sn' => 'Tin',
|
57
|
-
'Sb' => 'Antimony',
|
58
|
-
'Te' => 'Tellurium',
|
59
|
-
'I' => 'Iodine',
|
60
|
-
'Xe' => 'Xenon',
|
61
|
-
'Cs' => 'Cesium',
|
62
|
-
'Ba' => 'Barium',
|
63
|
-
'La' => 'Lanthanum',
|
64
|
-
'Ce' => 'Cerium',
|
65
|
-
'Pr' => 'Praseodymium',
|
66
|
-
'Nd' => 'Neodymium',
|
67
|
-
'Pm' => 'Promethium',
|
68
|
-
'Sm' => 'Samarium',
|
69
|
-
'Eu' => 'Europium',
|
70
|
-
'Gd' => 'Gadolinium',
|
71
|
-
'Tb' => 'Terbium',
|
72
|
-
'Dy' => 'Dysprosium',
|
73
|
-
'Ho' => 'Holmium',
|
74
|
-
'Er' => 'Erbium',
|
75
|
-
'Tm' => 'Thulium',
|
76
|
-
'Yb' => 'Ytterbium',
|
77
|
-
'Lu' => 'Lutetium',
|
78
|
-
'Hf' => 'Hafnium',
|
79
|
-
'Ta' => 'Tantalum',
|
80
|
-
'W' => 'Tungsten',
|
81
|
-
'Re' => 'Rhenium',
|
82
|
-
'Os' => 'Osmium',
|
83
|
-
'Ir' => 'Iridium',
|
84
|
-
'Pt' => 'Platinum',
|
85
|
-
'Au' => 'Gold',
|
86
|
-
'Hg' => 'Mercury',
|
87
|
-
'Tl' => 'Thallium',
|
88
|
-
'Pb' => 'Lead',
|
89
|
-
'Bi' => 'Bismuth',
|
90
|
-
'Po' => 'Polonium',
|
91
|
-
'At' => 'Astatine',
|
92
|
-
'Rn' => 'Radon',
|
93
|
-
'Fr' => 'Francium',
|
94
|
-
'Ra' => 'Radium',
|
95
|
-
'Ac' => 'Actinium',
|
96
|
-
'Th' => 'Thorium',
|
97
|
-
'Pa' => 'Protactinium',
|
98
|
-
'U' => 'Uranium',
|
99
|
-
'Np' => 'Neptunium',
|
100
|
-
'Pu' => 'Plutonium',
|
101
|
-
'Am' => 'Americium',
|
102
|
-
'Cm' => 'Curium',
|
103
|
-
'Bk' => 'Berkelium',
|
104
|
-
'Cf' => 'Californium',
|
105
|
-
'Es' => 'Einsteinium',
|
106
|
-
'Fm' => 'Fermium',
|
107
|
-
'Md' => 'Mendelevium',
|
108
|
-
'No' => 'Nobelium',
|
109
|
-
'Lr' => 'Lawrencium',
|
110
|
-
'Rf' => 'Rutherfordium',
|
111
|
-
'Db' => 'Dubnium',
|
112
|
-
'Sg' => 'Seaborgium',
|
113
|
-
'Bh' => 'Bohrium',
|
114
|
-
'Hs' => 'Hassium',
|
115
|
-
'Mt' => 'Meitnerium'
|
116
|
-
# add stable elements
|
117
|
-
}
|
118
|
-
|
119
|
-
# Define some extra methods for class String
|
120
|
-
class String
|
121
|
-
|
122
|
-
# Return true or false depending on
|
123
|
-
#if the element symbol exists
|
124
|
-
def element?
|
125
|
-
input = self.capitalize
|
126
|
-
if $elements[input].nil?
|
127
|
-
return false
|
128
|
-
else
|
129
|
-
return true
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# Use element? method to convert an
|
134
|
-
# element symbol into its name
|
135
|
-
def element
|
136
|
-
input = self.capitalize
|
137
|
-
if input.element?
|
138
|
-
puts $elements[input]
|
139
|
-
else
|
140
|
-
puts "'#{input}' is not an element symbol"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# Use the element? method to check if
|
145
|
-
# a string (that contains other words)
|
146
|
-
# contains element symbols
|
147
|
-
def contains_element?
|
148
|
-
input = self.capitalize
|
149
|
-
new = input.split ' '
|
150
|
-
$thing = 0
|
151
|
-
new.each do |i|
|
152
|
-
if i.element?
|
153
|
-
$thing += 1
|
154
|
-
end
|
155
|
-
end
|
156
|
-
if $thing > 0
|
157
|
-
return true
|
158
|
-
else
|
159
|
-
return false
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# Use the element? method to convert
|
165
|
-
# all symbols into the element name
|
166
|
-
|
167
|
-
# Try to get this working
|
168
|
-
|
169
|
-
# **Not working yet:** You can also convert all of the
|
170
|
-
# symbols in a string to their actual name
|
171
|
-
# ```ruby
|
172
|
-
# 'Never put H in balloons'.convert_all # => 'Never put Hydrogen in balloons'
|
173
|
-
# 'K and As are not good to consume'.convert_all # => 'Potassium and Arsenic are not good to consume'
|
174
|
-
# ```
|
175
|
-
|
176
|
-
# def convert_all
|
177
|
-
# input = self.capitalize
|
178
|
-
# keys = $elements.keys
|
179
|
-
# if input.element?
|
180
|
-
# $new = input.split ' '
|
181
|
-
# keys.each do |k|
|
182
|
-
# if $new.include? k
|
183
|
-
# $new = $new.gsub(k, $elements[k])
|
184
|
-
# end
|
185
|
-
# end
|
186
|
-
# puts $new.join ' '
|
187
|
-
# end
|
188
|
-
# end
|
189
|
-
|
190
|
-
# Create some methods for the Elementic class
|
191
|
-
class Elementic
|
192
|
-
# Elementic.version will `puts` the version
|
193
|
-
def self.version
|
194
|
-
puts Version::NUMBER
|
195
|
-
end
|
196
|
-
|
197
|
-
# Elementic.list will list all elements from hash
|
198
|
-
def self.list
|
199
|
-
$elements.each do |i|
|
200
|
-
print "#{i} \n"
|
201
|
-
end
|
202
|
-
return $elements.length
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
1
|
+
require_relative 'elementic/version'
|
2
|
+
require_relative 'elementic/periodic_table'
|
metadata
CHANGED
@@ -1,22 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elementic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: |-
|
42
|
+
A usable hash (and some methods to boot) of
|
43
|
+
the Periodic table of elements
|
14
44
|
email: joshception@icloud.com
|
15
45
|
executables: []
|
16
46
|
extensions: []
|
17
47
|
extra_rdoc_files: []
|
18
48
|
files:
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- elementic.gemspec
|
19
53
|
- lib/elementic.rb
|
54
|
+
- lib/elementic/element.rb
|
55
|
+
- lib/elementic/periodic_table.rb
|
56
|
+
- lib/elementic/version.rb
|
20
57
|
homepage: http://rubygems.org/gems/elementic
|
21
58
|
licenses:
|
22
59
|
- MIT
|
@@ -40,5 +77,5 @@ rubyforge_project:
|
|
40
77
|
rubygems_version: 2.4.2
|
41
78
|
signing_key:
|
42
79
|
specification_version: 4
|
43
|
-
summary:
|
80
|
+
summary: Easy chemistry in Ruby
|
44
81
|
test_files: []
|