Skip to content

Commit

Permalink
Merge af190b1 into 8e36284
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeasley committed Apr 10, 2019
2 parents 8e36284 + af190b1 commit ad090f7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
2.5.1
8 changes: 8 additions & 0 deletions lib/har/archive.rb
Expand Up @@ -72,6 +72,14 @@ def entries
@entries ||= raw_entries.map { |e| Entry.new(e) }
end

def entries_before(time)
raise TypeError, "expected Time" unless time.is_a?(Time)
entries.select do |entry|
return false unless entry.time
entry.started_date_time + entry.time / 1000.0 <= time
end
end

# create a new archive by merging this and another archive

def merge(other)
Expand Down
2 changes: 1 addition & 1 deletion lib/har/page.rb
Expand Up @@ -16,7 +16,7 @@ def entries_before(time)
raise TypeError, "expected Time" unless time.is_a?(Time)
entries.select do |entry|
return false unless entry.time
entry.started_date_time + entry.time / 1000.0 < time
entry.started_date_time + entry.time / 1000.0 <= time
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions spec/har/archive_spec.rb
Expand Up @@ -152,5 +152,22 @@ module HAR
end
end

describe "#entries_before" do
let(:archive) { Archive.from_file(google_path) }

it "requires a DateTime" do
expect { archive.entries_before("a string") }.to raise_error(TypeError)
end

it "filters entries that responded before the specified time" do
time = archive.pages.first.started_date_time + 0.250
entries = archive.entries_before(time)
entries.each do |entry|
(entry.started_date_time + entry.time / 1000.to_f).should < time
end

entries.length.should < archive.entries.length
end
end
end # Archive
end # HAR
2 changes: 2 additions & 0 deletions spec/har/page_spec.rb
Expand Up @@ -30,6 +30,8 @@ module HAR
entries.each do |entry|
(entry.started_date_time + entry.time / 1000.to_f).should < time
end

entries.length.should < page.entries.length
end
end
end
Expand Down

0 comments on commit ad090f7

Please sign in to comment.