$ gem install bubs
$ bubs is really useful
ⓘⓢ ⓡⓔⓐⓛⓛⓨ ⓤⓢⓔⓕⓤⓛ
Check Ruby-Toolbox.com and RubyGems.org first.
$ bundle gem elementy
create elementy/Gemfile
create elementy/Rakefile
create elementy/LICENSE.txt
create elementy/README.md
create elementy/.gitignore
create elementy/elementy.gemspec
create elementy/lib/elementy.rb
create elementy/lib/elementy/version.rb
# elementy.gemspec
Gem::Specification.new do |spec|
spec.name = "elementy"
spec.version = Elementy::VERSION
spec.authors = ["Josh Lewis"]
spec.email = ["josh.w.lewis@gmail.com"]
spec.description = "Lookup Data for Elements in the Periodic Table"
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^test/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
end
- number: 1
name: Hydrogen
molar: 1.00794
symbol: H
- number: 2
name: Helium
molar: 4.002602
symbol: He
# lib/elementy/element.rb
module Elementy
class Element
attr_accessor :number, :symbol, :name
def self.search(term)
if term =~ /\A\d*\Z/
find { |e| e.number == term.to_i }
else
find { |e| [e.symbol, e.name].include? term.upcase }
end
end
end
end
require 'test_helper'
describe Elementy::Element do
it '::all must be an array' do
Elementy::Element.all.must_be_instance_of Array
end
it 'must be Enumerable' do
Elementy::Element.must_be_kind_of Enumerable
end
describe 'search' do
it 'should find by number' do
Elementy::Element.search(12).must_be_instance_of Elementy::Element
end
end
end
# Searches for and returns an element if found.
#
# @param term [string, symbol, integer] the name,
# symbol, or atomic number to search for
# @return [Elementy::Element]
def search(term)
Elementy::Element.search term
end
# bin/elementy
#!/usr/bin/env ruby
$:.unshift File.expand_path('../../lib', __FILE__)
require 'elementy'
if args.include?("--version") || args.include?("-v")
p Elementy::VERSION
else
if element = Elementy::Element.search(args.first)
puts element.to_console
else
puts "Could not find element #{args.first}"
end
end
# lib/elementy/version.rb
module Elementy
VERSION = "0.1.0"
end
$ gem build elementy.gemspec
Successfully built RubyGem
Name: elementy
Version: 0.1.0
File: elementy-0.1.0.gem
$ gem push elementy-0.1.0.gem
Pushing gem to https://rubygems.org...
Successfully registered gem: elementy (0.1.0)
$ gem install elementy
Successfully installed elementy-0.1.0
1 gem installed
$ elementy 42
symbol: Mo
name: Molybdenum
number: 42
molar: 95.96
position: 5
group: Element Transition d
electrons: [2, 8, 18, 13, 1]