Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

workgena/sp_test_ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sp_test_ruby

  • main - implementation with Array data structure
  • Pull Request #1 - implementation with Hash data structure

How to run

$ ./parser.rb webserver.log
  -- or --
$ ruby parser.rb webserver.log

Example output

$ ./parser.rb webserver.log

> list of webpages with most page views ordered from most pages views to less page views
  /about/2             90   visits
  /contact             89   visits
  /index               82   visits
  /about               81   visits
  /help_page/1         80   visits
  /home                78   visits

> list of webpages with most unique page views also ordered
  /index               23   unique views
  /home                23   unique views
  /contact             23   unique views
  /help_page/1         23   unique views
  /about/2             22   unique views
  /about               21   unique views

Explanations

  • I've chose File.each_line to reduce memory usage
  • Core Data Structure to store "pages" is Array. It's not efficient, and can be replaced with HashMap in the future. HashMap makes insertion faster, but require conversion to Array when sorting. This change should be easy - #1
  • Why sort_by() + reverse() - performance is acceptable, can be changed just to sort_by with a block
  • printf "%-20s %-4s visits\n" is not robust solution, but don't want to spend to match time on it

TODOs

  • Check performance with bigger files, compare to HashMap data structure
  • Security: prevent reading files from other directories
  • GitHub Action for RSpec and Rubocpo
  • Wrap every class with module (e.g. WebserverLogReader::)

Coverage snapshot

coverage_snapshot

  • parser.rb
  • lib/formatter/cli_by_unique_views.rb
  • lib/formatter/cli_by_views.rb

Those files are not covered, because they are related to presentation, not the logic. But mainly - lack of time.

Development

Install, run tests, run linter, run script itself

$ bundle
$ bundle exec rspec
$ bundle exec rubocop -a
$ ruby parser.rb webserver.log

About

Practice

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages