Class: PDG::ParticleTable
- Inherits:
-
Hash
- Object
- Hash
- PDG::ParticleTable
- Defined in:
- lib/pdg/particle_table.rb
Instance Method Summary collapse
-
#<<(particle) ⇒ Object
Appends a new particle to the ‘particles` hash.
- #[](id) ⇒ Object
-
#initialize(path) ⇒ ParticleTable
constructor
A new instance of ParticleTable.
-
#pretty_print(id, fields = [:id, :name, :mass, :charge, :width, :lifetime]) ⇒ Object
Returns a formatted table containing particle(s) with id(s) = ‘ids` One may specify a single integer, an Array of them, or a Range.
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ ParticleTable
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pdg/particle_table.rb', line 5 def initialize(path) source = File.new path, "r" while (line = source.gets) line_type = PDG::single_character(line) case line_type # Comment lines begin with a * when "*" next when "M" parse_line line, :mass when "W" parse_line line, :width end end source.close end |
Instance Method Details
#<<(particle) ⇒ Object
Appends a new particle to the ‘particles` hash
67 68 69 |
# File 'lib/pdg/particle_table.rb', line 67 def <<(particle) self[particle.id] = particle end |
#[](id) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/pdg/particle_table.rb', line 58 def [](id) if id.class == Range or id.class == Array self.values_at(*id).compact else self.values_at(id).first end end |
#pretty_print(id, fields = [:id, :name, :mass, :charge, :width, :lifetime]) ⇒ Object
Returns a formatted table containing particle(s) with id(s) = ‘ids` One may specify a single integer, an Array of them, or a Range
77 78 79 |
# File 'lib/pdg/particle_table.rb', line 77 def pretty_print(id, fields = [:id, :name, :mass, :charge, :width, :lifetime]) PDG::pretty_print(self[id], fields) end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/pdg/particle_table.rb', line 71 def to_s "<##{self.class}:#{self.object_id.to_s(8)}>" end |