elementy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/elementy.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'elementy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "elementy"
8
+ spec.version = Elementy::VERSION
9
+ spec.authors = ["Josh Lewis"]
10
+ spec.email = ["josh.w.lewis@gmail.com"]
11
+ spec.description = "Lookup Data for Elements in the Periodic Table"
12
+ spec.summary = "Lookup Data for Elements in the Periodic Table"
13
+ spec.homepage = "https://github.com/joshwlewis/elementy"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/elementy.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "elementy/version"
2
+ require "elementy/element"
3
+
4
+ module Elementy
5
+ class << self
6
+ def root
7
+ File.dirname(File.dirname(__FILE__))
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ require 'yaml'
2
+ module Elementy
3
+ class Element
4
+ attr_accessor :number, :symbol, :name, :molar, :group, :position, :electrons
5
+
6
+ class << self
7
+ include Enumerable
8
+ def all
9
+ @all ||= defaults.map { |d| new d }
10
+ end
11
+
12
+ def each
13
+ all.each { |e| yield e }
14
+ end
15
+
16
+ def defaults
17
+ YAML.load(File.open "#{Elementy.root}/data/elements.yaml")
18
+ end
19
+
20
+ def search(term)
21
+ if term.is_a?(Numeric) || term =~ /\A\d*\Z/
22
+ find { |e| e.number == term.to_i}
23
+ else
24
+ find { |e| [e.symbol, e.name].any? { |a| a.upcase == term.to_s.upcase} }
25
+ end
26
+ end
27
+ end
28
+
29
+ def initialize(attributes)
30
+ attributes.each do |k,v|
31
+ send "#{k}=", v
32
+ end
33
+ end
34
+
35
+ def to_hash
36
+ { symbol: symbol, name: name, number: number, molar: molar,
37
+ position: position, group: group, electrons: electrons }
38
+ end
39
+
40
+ def to_console
41
+ to_hash.map do |k,v|
42
+ " #{k}:#{' ' * (12-k.length)}#{v}"
43
+ end.join("\n")
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Elementy
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ describe Elementy::Element do
4
+ it '::all must be an array' do
5
+ Elementy::Element.all.must_be_instance_of Array
6
+ end
7
+
8
+ it "must be Enumerable" do
9
+ Elementy::Element.must_be_kind_of Enumerable
10
+ end
11
+
12
+ describe "search" do
13
+ it "should find by number" do
14
+ Elementy::Element.search(12).must_be_instance_of Elementy::Element
15
+ end
16
+
17
+ it "should find by number string" do
18
+ Elementy::Element.search('17').must_be_instance_of Elementy::Element
19
+ end
20
+
21
+ it "should find by symbol" do
22
+ Elementy::Element.search(:h).must_be_instance_of Elementy::Element
23
+ end
24
+
25
+ it "should find by symbol string" do
26
+ Elementy::Element.search("h").must_be_instance_of Elementy::Element
27
+ end
28
+
29
+ it "should find by name" do
30
+ Elementy::Element.search("helium").must_be_instance_of Elementy::Element
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+
4
+ require 'elementy'
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elementy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Lewis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Lookup Data for Elements in the Periodic Table
47
+ email:
48
+ - josh.w.lewis@gmail.com
49
+ executables:
50
+ - elementy
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/elementy
60
+ - data/elements.yaml
61
+ - elementy.gemspec
62
+ - lib/elementy.rb
63
+ - lib/elementy/element.rb
64
+ - lib/elementy/version.rb
65
+ - test/lib/element_test.rb
66
+ - test/test_helper.rb
67
+ homepage: https://github.com/joshwlewis/elementy
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.23
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Lookup Data for Elements in the Periodic Table
92
+ test_files:
93
+ - test/lib/element_test.rb
94
+ - test/test_helper.rb