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
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
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 15 def add_column() () = () name = [:name] columns[name] = define_method(name) do @data[name] end end |
#columns ⇒ Object
7 8 9 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 7 def columns @columns ||= {} end |
#create_record(line) ⇒ Object
42 43 44 45 46 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 42 def create_record(line) record = new(line) return record if record.valid? return nil end |
#each(&block) ⇒ Object
54 55 56 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 54 def each(&block) columns.each(&block) end |
#parse(line) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 27 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 = {} columns.each do |name, | val = match_data[[:pos]] data[name] = convert(val, [:conversion]) end data end |
#set_column_custom_options(column_name, options) ⇒ Object
48 49 50 51 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 48 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
11 12 13 |
# File 'lib/logfile_interval/parsed_line/parser.rb', line 11 def set_regex(regex) @regex = regex end |