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 : "iaea" @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
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(={}) @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 "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
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
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(={}) @resource = "external" build() return self end |
#resources ⇒ Object
25 26 27 |
# File 'lib/radiation/source.rb', line 25 def resources ["iaea", "nucleide.org"] end |