class Elt::Elt

Public Class Methods

new() click to toggle source
# File lib/elt.rb, line 4
def initialize
  gemdir = File.dirname File.dirname __FILE__
  @dictionary_path = gemdir + '/' + 'elements.txt'
end

Public Instance Methods

lookup(term) click to toggle source
# File lib/elt.rb, line 9
def lookup(term)
  File.open(@dictionary_path, 'r') do |dict|
    dict.each_line do |line_nl|
      row = line_nl.chomp.split
      if row.include?(term)
        return row
      end
    end
  end
  return nil
end
run() click to toggle source
# File lib/elt.rb, line 29
def run
  case ARGV.size
  when 1
    row = lookup(ARGV[0])
    if row
      show(row)
    else
      puts 'Not found'
    end
  else
    usage
  end
end
show((atomic_number, name, symbol)) click to toggle source
# File lib/elt.rb, line 21
def show((atomic_number, name, symbol))
  puts "#{atomic_number} #{name} #{symbol}"
end
usage() click to toggle source
# File lib/elt.rb, line 25
def usage
  puts "Usage: elt NAME_NUMBER_OR_SYMBOL"
end