Class: ToiletTracker::Parsers::WhatsappParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/toilet_tracker/parsers/whatsapp_parser.rb

Instance Attribute Summary

Attributes inherited from BaseParser

#config

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize

Constructor Details

This class inherits a constructor from ToiletTracker::Parsers::BaseParser

Instance Method Details

#parse(line) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/toilet_tracker/parsers/whatsapp_parser.rb', line 6

def parse(line)
  match = config.whatsapp_message_pattern.match(line)
  return failure_for_invalid_format(line) unless match

  begin
    message = build_message_from_match(match)
    return failure_for_invalid_sender(line) unless message.valid?

    Core::Result.success(message)
  rescue StandardError => e
    Core::Result.failure(e)
  end
end

#valid?(line) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/toilet_tracker/parsers/whatsapp_parser.rb', line 20

def valid?(line)
  config.whatsapp_message_pattern.match?(line)
end