Module: LogfileInterval::ParsedLine::Parser
- Included in:
- Base
- Defined in:
- lib/logfile_interval/parsed_line/parser.rb
Instance Attribute Summary collapse
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Instance Method Summary collapse
- #add_column(options) ⇒ Object
- #columns ⇒ Object
- #create_record(line) ⇒ Object
- #each(&block) ⇒ Object
- #parse(line) ⇒ Object
- #set_column_custom_options(column_name, options) ⇒ Object
- #set_regex(regex) ⇒ Object
- #skip(options) ⇒ Object
- #skip_columns ⇒ Object
- #skip_columns_with_exceptions ⇒ Object
- #skip_with_exceptions(options) ⇒ Object
Instance Attribute Details
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
6 7 8 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 6 def regex @regex end |
Instance Method Details
#add_column(options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 24 def add_column() () = () name = [:name] columns[name] = define_method(name) do @data[name] end end |
#columns ⇒ Object
8 9 10 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 8 def columns @columns ||= {} end |
#create_record(line) ⇒ Object
76 77 78 79 80 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 76 def create_record(line) record = new(line) return record if record.valid? return nil end |
#each(&block) ⇒ Object
88 89 90 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 88 def each(&block) columns.each(&block) end |
#parse(line) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 52 def parse(line) raise ConfigurationError, 'There must be at least 1 configured column' unless columns.any? raise ConfigurationError, 'A regex must be set' unless regex match_data = regex.match(line) return nil unless match_data data = { skip: false } columns.each do |name, | val = match_data[[:pos]] data[name] = convert(val, [:conversion]) end skip_columns.each do || val = match_data[[:pos]] if val =~ [:regex] data[:skip] = true break end end data end |
#set_column_custom_options(column_name, options) ⇒ Object
82 83 84 85 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 82 def (column_name, ) raise ArgumentError, "Invalid column name: #{column_name}" unless columns.has_key?(column_name) columns[column_name][:custom_options] = end |
#set_regex(regex) ⇒ Object
20 21 22 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 20 def set_regex(regex) @regex = regex end |
#skip(options) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 36 def skip() unless [:pos] && [:regex] raise ConfigurationError, "skip option must include pos and regex" end skip_columns << { pos: [:pos], regex: [:regex] } end |
#skip_columns ⇒ Object
12 13 14 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 12 def skip_columns @skip_columns ||= [] end |
#skip_columns_with_exceptions ⇒ Object
16 17 18 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 16 def skip_columns_with_exceptions @skip_columns_with_exceptions ||= [] end |
#skip_with_exceptions(options) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 44 def skip_with_exceptions() unless [:pos] && [:regex] raise ConfigurationError, "skip option must include pos and regex" end skip_columns_with_exceptions << { pos: [:pos], regex: [:regex] } end |