Class: Radiation::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/radiation/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Source

Returns a new instance of Source.



6
7
8
9
10
# 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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/radiation/source.rb', line 4

def description
  @description
end

#halflifeObject (readonly)

Returns the value of attribute halflife.



4
5
6
# File 'lib/radiation/source.rb', line 4

def halflife
  @halflife
end

#nuclideObject (readonly)

Returns the value of attribute nuclide.



4
5
6
# File 'lib/radiation/source.rb', line 4

def nuclide
  @nuclide
end

#referenceObject (readonly)

Returns the value of attribute reference.



4
5
6
# File 'lib/radiation/source.rb', line 4

def reference
  @reference
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/radiation/source.rb', line 4

def resource
  @resource
end

#transitionsObject (readonly)

Returns the value of attribute transitions.



4
5
6
# File 'lib/radiation/source.rb', line 4

def transitions
  @transitions
end

Instance Method Details

#energiesObject



35
36
37
# File 'lib/radiation/source.rb', line 35

def energies
	self.transitions.collect{|line| line[:energy]}
end

#fetch(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# 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

#intensitiesObject



39
40
41
# 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) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# 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 = {}) ⇒ Object



29
30
31
32
33
# File 'lib/radiation/source.rb', line 29

def read(options={})
	@resource = "external"
	build(options)
	return self
end

#resourcesObject



25
26
27
# File 'lib/radiation/source.rb', line 25

def resources
	["iaea", "nucleide.org"]
end