Class: Legion::Extensions::Agentic::Homeostasis::Tectonics::Helpers::SeismicEvent
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Tectonics::Helpers::SeismicEvent
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb
Constant Summary collapse
- EVENT_TYPES =
%i[earthquake tremor aftershock].freeze
Constants included from Constants
Constants::AFTERSHOCK_DECAY, Constants::BOUNDARY_TYPES, Constants::COLLISION_THRESHOLD, Constants::MAGNITUDE_LABELS, Constants::MAX_DRIFT_RATE, Constants::MAX_PLATES, Constants::MAX_QUAKES, Constants::MIN_DRIFT_RATE, Constants::PLATE_STATES, Constants::STRESS_QUAKE_TRIGGER, Constants::SUBDUCTION_RATIO
Instance Attribute Summary collapse
-
#affected_plate_ids ⇒ Object
readonly
Returns the value of attribute affected_plate_ids.
-
#epicenter_plate_id ⇒ Object
readonly
Returns the value of attribute epicenter_plate_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#magnitude ⇒ Object
readonly
Returns the value of attribute magnitude.
-
#parent_event_id ⇒ Object
readonly
Returns the value of attribute parent_event_id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #aftershock? ⇒ Boolean
-
#initialize(type:, magnitude:, epicenter_plate_id:, affected_plate_ids: [], parent_event_id: nil) ⇒ SeismicEvent
constructor
A new instance of SeismicEvent.
- #label ⇒ Object
- #to_h ⇒ Object
Methods included from Constants
Constructor Details
#initialize(type:, magnitude:, epicenter_plate_id:, affected_plate_ids: [], parent_event_id: nil) ⇒ SeismicEvent
Returns a new instance of SeismicEvent.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 19 def initialize(type:, magnitude:, epicenter_plate_id:, affected_plate_ids: [], parent_event_id: nil, **) raise ArgumentError, "unknown event type: #{type.inspect}" unless EVENT_TYPES.include?(type) @id = SecureRandom.uuid @type = type @magnitude = magnitude.clamp(0.0, Float::INFINITY) @epicenter_plate_id = epicenter_plate_id @affected_plate_ids = Array(affected_plate_ids) @parent_event_id = parent_event_id @timestamp = Time.now.utc end |
Instance Attribute Details
#affected_plate_ids ⇒ Object (readonly)
Returns the value of attribute affected_plate_ids.
16 17 18 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16 def affected_plate_ids @affected_plate_ids end |
#epicenter_plate_id ⇒ Object (readonly)
Returns the value of attribute epicenter_plate_id.
16 17 18 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16 def epicenter_plate_id @epicenter_plate_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16 def id @id end |
#magnitude ⇒ Object (readonly)
Returns the value of attribute magnitude.
16 17 18 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16 def magnitude @magnitude end |
#parent_event_id ⇒ Object (readonly)
Returns the value of attribute parent_event_id.
16 17 18 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16 def parent_event_id @parent_event_id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
16 17 18 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 16 def type @type end |
Instance Method Details
#aftershock? ⇒ Boolean
31 32 33 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 31 def aftershock? @type == :aftershock end |
#label ⇒ Object
35 36 37 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 35 def label label_for(@magnitude) end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/homeostasis/tectonics/helpers/seismic_event.rb', line 39 def to_h { id: @id, type: @type, magnitude: @magnitude, label: label, epicenter_plate_id: @epicenter_plate_id, affected_plate_ids: @affected_plate_ids, parent_event_id: @parent_event_id, timestamp: @timestamp } end |