Class: Pipio::BasicParser
- Inherits:
-
Object
- Object
- Pipio::BasicParser
- Defined in:
- lib/pipio/parsers/basic_parser.rb
Instance Method Summary collapse
- #create_message(match_data) ⇒ Object
- #create_status_or_event_message(match_data) ⇒ Object
-
#initialize(source_file_path, my_aliases, line_regex, line_regex_status, cleaner) ⇒ BasicParser
constructor
A new instance of BasicParser.
-
#parse ⇒ Object
This method returns a Chat instance, or false if it could not parse the file.
-
#pre_parse ⇒ Object
Extract required data from the file.
- #time_parser ⇒ Object
Constructor Details
#initialize(source_file_path, my_aliases, line_regex, line_regex_status, cleaner) ⇒ BasicParser
Returns a new instance of BasicParser.
3 4 5 6 7 8 9 10 |
# File 'lib/pipio/parsers/basic_parser.rb', line 3 def initialize(source_file_path, my_aliases, line_regex, line_regex_status, cleaner) @my_aliases = my_aliases @line_regex = line_regex @line_regex_status = line_regex_status @my_alias = @my_aliases.first @file_reader = FileReader.new(source_file_path, cleaner) end |
Instance Method Details
#create_message(match_data) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pipio/parsers/basic_parser.rb', line 43 def (match_data) # Either a regular message line or an auto-reply/away message. time = time_parser.parse(match_data[:timestamp]) if time my_alias = match_data[:sn_or_alias] my_screen_name = @alias_registry[my_alias] body = match_data[:body] is_auto_reply = match_data[:auto_reply] AutoOrXmlMessageCreator.new(body, time, my_screen_name, my_alias, is_auto_reply).create end end |
#create_status_or_event_message(match_data) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/pipio/parsers/basic_parser.rb', line 56 def (match_data) time = time_parser.parse(match_data[:timestamp]) str = match_data[:body] if time && event_we_care_about?(str) (str, time) || (str, time) end end |
#parse ⇒ Object
This method returns a Chat instance, or false if it could not parse the file.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pipio/parsers/basic_parser.rb', line 14 def parse if pre_parse = @file_reader.other_lines.map do |line| = @line_regex.match(line) = @line_regex_status.match(line) if () elsif () end end Chat.new(, @metadata) end end |
#pre_parse ⇒ Object
Extract required data from the file. Run by parse.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pipio/parsers/basic_parser.rb', line 31 def pre_parse @file_reader.read = Metadata.new(MetadataParser.new(@file_reader.first_line).parse) if .valid? @metadata = @alias_registry = AliasRegistry.new(@metadata.their_screen_name) @my_aliases.each do |my_alias| @alias_registry[my_alias] = @metadata.my_screen_name end end end |
#time_parser ⇒ Object
65 66 67 |
# File 'lib/pipio/parsers/basic_parser.rb', line 65 def time_parser @time_parser ||= TimeParser.new(@metadata.start_year, @metadata.start_month, @metadata.start_mday) end |