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 : "internal"
	@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



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

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

#fetch(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# 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 "internal" then Radiation::Resource::Internal.new.fetch(@nuclide).data
		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



40
41
42
# File 'lib/radiation/source.rb', line 40

def intensities
	self.transitions.select{|line| line[:intensity] > 0}.collect{|line| {:energy => line[:energy], :intensity => line[:intensity]} }
end

#is_nuclide?(nuclide) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/radiation/source.rb', line 44

def is_nuclide?(nuclide)
	!!(nuclide =~ /\A[a-zA-Z]{1,2}-\d{1,3}\z/)
end

#read(options = {}) ⇒ Object



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

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

#resourcesObject



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

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