Class: Radiation::Source
- Inherits:
-
Object
- Object
- Radiation::Source
- Defined in:
- lib/radiation/source.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#halflife ⇒ Object
readonly
Returns the value of attribute halflife.
-
#nuclide ⇒ Object
readonly
Returns the value of attribute nuclide.
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
- #energies ⇒ Object
- #fetch(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Source
constructor
A new instance of Source.
- #intensities ⇒ Object
- #is_nuclide?(nuclide) ⇒ Boolean
- #read(options = {}) ⇒ Object
- #resources ⇒ Object
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(={}) @resource = .key?(:resource) ? [:resource].to_s : "internal" @nuclide = [:nuclide].to_s if .key?(:nuclide) fetch if @resource and @nuclide end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/radiation/source.rb', line 4 def description @description end |
#halflife ⇒ Object (readonly)
Returns the value of attribute halflife.
4 5 6 |
# File 'lib/radiation/source.rb', line 4 def halflife @halflife end |
#nuclide ⇒ Object (readonly)
Returns the value of attribute nuclide.
4 5 6 |
# File 'lib/radiation/source.rb', line 4 def nuclide @nuclide end |
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
4 5 6 |
# File 'lib/radiation/source.rb', line 4 def reference @reference end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/radiation/source.rb', line 4 def resource @resource end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
4 5 6 |
# File 'lib/radiation/source.rb', line 4 def transitions @transitions end |
Instance Method Details
#energies ⇒ Object
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(={}) @resource = [:resource].to_s if .key?(:resource) @nuclide = [:nuclide].to_s if .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 |
#intensities ⇒ Object
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
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(={}) @resource = "external" build() return self end |
#resources ⇒ Object
26 27 28 |
# File 'lib/radiation/source.rb', line 26 def resources ["internal", "iaea", "nucleide.org"] end |