class Radiation::Source

Attributes

description[R]
halflife[R]
nuclide[R]
reference[R]
resource[R]
transitions[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/radiation/source.rb, line 6
def initialize(options={})
        @resource = options.key?(:resource) ? options[:resource].to_s : "iaea"
        @nuclide  = options[:nuclide].to_s if options.key?(:nuclide)
        fetch if @resource and @nuclide
end

Public Instance Methods

energies() click to toggle source
# File lib/radiation/source.rb, line 35
def energies
        self.transitions.collect{|line| line[:energy]}
end
fetch(options={}) click to toggle source
# File lib/radiation/source.rb, line 12
def fetch(options={})
        @resource = options[:resource].to_s if options.key?(:resource)
        @nuclide  = options[:nuclide].to_s  if options.key?(:nuclide)
        raise "Nuclide: #{@nuclide} is not valid." unless is_nuclide?(@nuclide)
        data = case @resource
                when "iaea" then Radiation::Resource::IAEA.new.fetch(@nuclide).data
                when "nucleide.org" then Radiation::Resource::Nucleideorg.new.fetch(@nuclide).data
                else raise "Unknown Datasource"
        end
        build(data)
        return self
end
intensities() click to toggle source
# File lib/radiation/source.rb, line 39
def intensities
        self.transitions.select{|line| line[:intensity] > 0}.collect{|line| {:energy => line[:energy], :intensity => line[:intensity]} }
end
is_nuclide?(nuclide) click to toggle source
# File lib/radiation/source.rb, line 43
def is_nuclide?(nuclide)
        !!(nuclide =~ /\A[a-zA-Z]{1,2}-\d{1,3}\z/)
end
read(options={}) click to toggle source
# File lib/radiation/source.rb, line 29
def read(options={})
        @resource = "external"
        build(options)
        return self
end
resources() click to toggle source
# File lib/radiation/source.rb, line 25
def resources
        ["iaea", "nucleide.org"]
end

Private Instance Methods

build(data) click to toggle source
# File lib/radiation/source.rb, line 48
def build(data)
        [:nuclide, :halflife, :reference, :description, :transitions].each do |key|
                instance_variable_set("@#{key}", data[key]) if data.key?(key)
        end
end