Skip to content

Instantly share code, notes, and snippets.

@vovs03
Created May 25, 2022 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vovs03/df3964b6bd9bf84e16579f7794d414c3 to your computer and use it in GitHub Desktop.
Save vovs03/df3964b6bd9bf84e16579f7794d414c3 to your computer and use it in GitHub Desktop.
log_line_parser.rb for Exercism/string
class LogLineParser
@@lvl = ''
@@msg = ''
def initialize(line)
@line = line
#@msg = msg
#@lvl = lvl
end
def message
#raise 'Please implement the LogLineParser#message method'
#%q{...}
#'Disk almost full' || 'Stack overflow' #||
#"#{[LEVEL]} : #{MESSAGE}"
#line.new('[ERROR]: Invalid operation')
#__LINE__
#@line.split(":")[1].slice(0).gsub(" ", "") #+ @line.split(":")[1]
# .strip - delete all backspaces
@@msg = @line.split(":")[1].strip
end
def log_level
#raise 'Please implement the LogLineParser#log_level method'
# Ruby I.Simdyanov p.70-72 Strings
@@lvl = @line.split(":")[0].downcase[1..-2] #.(/^[a-z]/)
end
def reformat
#raise 'Please implement the LogLineParser#reformat method'
#message() +
ref = @line.split(":")[1].strip
ref_e = @line.split(":")[0].downcase[1..-2]
"#{ref} (#{ref_e})"
#"#{@@msg} (#{@@lvl})"
#@line = "#{@lvl}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment