Class: IngvQuake::BasicInfoEventParser
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- IngvQuake::BasicInfoEventParser
- Defined in:
- lib/ingv_quake/services/basic_info_event_parser.rb
Overview
The BasicInfoEventParser class is responsible for parsing response data containing basic information about earthquake events. It inherits from the ApplicationService base class.
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#call ⇒ Array<BasicInfoEvent>
Parses the response data and creates an array of BasicInfoEvent objects.
-
#initialize(response) ⇒ BasicInfoEventParser
constructor
Initializes a new BasicInfoEventParser instance with the response data.
Methods inherited from ApplicationService
Constructor Details
#initialize(response) ⇒ BasicInfoEventParser
Initializes a new BasicInfoEventParser instance with the response data.
13 14 15 |
# File 'lib/ingv_quake/services/basic_info_event_parser.rb', line 13 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/ingv_quake/services/basic_info_event_parser.rb', line 8 def response @response end |
Instance Method Details
#call ⇒ Array<BasicInfoEvent>
Parses the response data and creates an array of BasicInfoEvent objects.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ingv_quake/services/basic_info_event_parser.rb', line 20 def call @response.lines.drop(1).map do |line| event_data = line.strip.split('|') attributes = { event_id: event_data[0], time: event_data[1], latitude: event_data[2], longitude: event_data[3], depth_km: event_data[4], author: event_data[5], catalog: event_data[6], contributor: event_data[7], contributor_id: event_data[8], mag_type: event_data[9], magnitude: event_data[10], mag_author: event_data[11], location: event_data[12], type: event_data[13] } magnitude = attributes[:magnitude].to_f if magnitude >= 3.0 event_id = attributes[:event_id] url_prefix = "http://shakemap.rm.ingv.it/shake4/data/#{event_id}/current/products/" attributes[:intensity_map] = "#{url_prefix}intensity.jpg" attributes[:pga_map] = "#{url_prefix}pga.jpg" attributes[:pgv_map] = "#{url_prefix}pgv.jpg" end BasicInfoEvent.new(**attributes) end end |