Class: TestingYourLegacy::RawFile

Inherits:
Object
  • Object
show all
Defined in:
lib/testing_your_legacy/raw_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, count = 25) ⇒ RawFile

Returns a new instance of RawFile.



6
7
8
9
# File 'lib/testing_your_legacy/raw_file.rb', line 6

def initialize(file,count = 25)
  @file  = file
  @count = count
end

Instance Method Details

#eachObject



11
12
13
# File 'lib/testing_your_legacy/raw_file.rb', line 11

def each
  to_log_summary.each { |record| yield record }
end

#int_to_id(url) ⇒ Object



33
34
35
# File 'lib/testing_your_legacy/raw_file.rb', line 33

def int_to_id(url)
  url.gsub(/\d+/,"id").gsub(/\?.*/,"?search_string")
end

#parsed_urlsObject



37
38
39
40
41
# File 'lib/testing_your_legacy/raw_file.rb', line 37

def parsed_urls
  @parsed_urls ||= started_only.map do |line|
    line.match(/^Started (?<protocol>\w+) "(?<url>.*)"/)
  end
end

#started_onlyObject



43
44
45
46
47
# File 'lib/testing_your_legacy/raw_file.rb', line 43

def started_only
  @started_only ||= @file.select { |line| 
    line.match(/^Started/) && !line.match(/assets/)
  }
end

#sumObject



27
28
29
30
31
# File 'lib/testing_your_legacy/raw_file.rb', line 27

def sum
  @sum ||= parsed_urls.each_with_object(Hash.new(0)) do |url,memo|
    memo[[int_to_id(url[:url]),url[:protocol]]] += 1
  end
end

#to_aObject



19
20
21
22
23
24
25
# File 'lib/testing_your_legacy/raw_file.rb', line 19

def to_a
  sum.keys.each_with_object([]) do | key, memo | 
    memo << TestingYourLegacy::LogEntry.new(key[0],
                                            key[1],
                                            sum[key])
  end
end

#to_log_summaryObject



15
16
17
# File 'lib/testing_your_legacy/raw_file.rb', line 15

def to_log_summary
  TestingYourLegacy::LogSummary.new(to_a)
end