Class: CassetteExplorer::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/cassette_explorer/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Reader

Returns a new instance of Reader.



3
4
5
# File 'lib/cassette_explorer/reader.rb', line 3

def initialize(path)
  @path = File.expand_path(path)
end

Instance Method Details

#readObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cassette_explorer/reader.rb', line 7

def read

  files = Dir["#{@path}/**/**"]

  sections = {}

  files.reject{ |f| File.directory? f }.each do |file|
    section_name = section_name_from_file_path(file)
    sections[section_name] ||= []

    data = YAML.load_file(file)
    if data['http_interactions']
      data['http_interactions'].each do |request|
        sections[section_name].push Page.new(request)
      end
    end
  end

  sections
end

#section_name_from_file_path(file_path) ⇒ Object



28
29
30
# File 'lib/cassette_explorer/reader.rb', line 28

def section_name_from_file_path(file_path)
  file_path.gsub(@path, '')
end