Class: ToiletTracker::Services::AnalysisService
- Inherits:
-
Object
- Object
- ToiletTracker::Services::AnalysisService
- Defined in:
- lib/toilet_tracker/services/analysis_service.rb
Instance Attribute Summary collapse
-
#message_parser ⇒ Object
readonly
Returns the value of attribute message_parser.
-
#shift_service ⇒ Object
readonly
Returns the value of attribute shift_service.
-
#timezone_service ⇒ Object
readonly
Returns the value of attribute timezone_service.
-
#whatsapp_parser ⇒ Object
readonly
Returns the value of attribute whatsapp_parser.
Instance Method Summary collapse
- #analyze_line(line) ⇒ Object
- #analyze_lines(lines) ⇒ Object
- #analyze_messages(messages, apply_retroactive_shifts: true) ⇒ Object
-
#initialize(whatsapp_parser: Parsers::WhatsappParser.new, message_parser: Parsers::MessageParser.new, shift_service: ShiftService.new, timezone_service: TimezoneService.new) ⇒ AnalysisService
constructor
A new instance of AnalysisService.
Constructor Details
#initialize(whatsapp_parser: Parsers::WhatsappParser.new, message_parser: Parsers::MessageParser.new, shift_service: ShiftService.new, timezone_service: TimezoneService.new) ⇒ AnalysisService
Returns a new instance of AnalysisService.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 8 def initialize( whatsapp_parser: Parsers::WhatsappParser.new, message_parser: Parsers::MessageParser.new, shift_service: ShiftService.new, timezone_service: TimezoneService.new ) @whatsapp_parser = whatsapp_parser = @shift_service = shift_service @timezone_service = timezone_service end |
Instance Attribute Details
#message_parser ⇒ Object (readonly)
Returns the value of attribute message_parser.
6 7 8 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 6 def end |
#shift_service ⇒ Object (readonly)
Returns the value of attribute shift_service.
6 7 8 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 6 def shift_service @shift_service end |
#timezone_service ⇒ Object (readonly)
Returns the value of attribute timezone_service.
6 7 8 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 6 def timezone_service @timezone_service end |
#whatsapp_parser ⇒ Object (readonly)
Returns the value of attribute whatsapp_parser.
6 7 8 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 6 def whatsapp_parser @whatsapp_parser end |
Instance Method Details
#analyze_line(line) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 28 def analyze_line(line) # Parse WhatsApp line format first whatsapp_result = whatsapp_parser.parse(line) return create_error_result(whatsapp_result.error, line) if whatsapp_result.failure? = whatsapp_result.value # Parse message content for toilet tracking commands = .parse() return create_error_result(.error, line) if .failure? parsed_result = .value return nil unless parsed_result # Not a toilet tracking message # Process the parsed result process_parsed_result(parsed_result) end |
#analyze_lines(lines) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 20 def analyze_lines(lines) # Parse all lines first results = lines.filter_map { |line| analyze_line(line) } # Apply retroactive shifts apply_retroactive_shifts_to_results(results) end |
#analyze_messages(messages, apply_retroactive_shifts: true) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/toilet_tracker/services/analysis_service.rb', line 46 def (, apply_retroactive_shifts: true) results = [] # First pass: process all messages and build shift history .each do || = .parse() next if .failure? || .value.nil? result = process_parsed_result(.value) results << result if result end # Second pass: apply retroactive shifts to poop events if enabled results = apply_retroactive_shifts_to_results(results) if apply_retroactive_shifts results end |