Class: Reporter::Dump

Inherits:
Object
  • Object
show all
Defined in:
lib/reporter/dump.rb

Overview

Public: Represents a dump of data exported from Reporter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Dump

Public: Initialize a new Dump from the dump contents

contents - An object that responds to #to_s. Represents the raw

serialized contents loaded from the dump.

Examples

Reporter::Dump.new('{"foo": "bar"}')
# => #<Reporter::Dump:0x1234 @contents="{\"foo\": \"bar\"}">


37
38
39
# File 'lib/reporter/dump.rb', line 37

def initialize(contents)
  @contents = contents.to_s
end

Instance Attribute Details

#contentsObject

Internal: Returns a String with the raw contents of the dump.



26
27
28
# File 'lib/reporter/dump.rb', line 26

def contents
  @contents
end

Class Method Details

.from_file(path) ⇒ Object

Public: Load a Reporter dump from a file on disk.

path - An object that responds to #to_s. Represents the path to

the file on disk to be loaded.

Examples

Reporter::Dump.from_file("/path/to/dump.json")
# => #<Reporter::Dump:0x1234 @contents="...">

Returns the Dump object representing the loaded dump. Raises Errno::ENOENT if the file cannot be found. Raises Errno::EACCES if the file cannot be accessed.



21
22
23
# File 'lib/reporter/dump.rb', line 21

def self.from_file(path)
  new(File.read(path.to_s))
end

Instance Method Details

#questionsObject

Public: Retrieves the list of questions in this Reporter dump.

Returns an Array of Reporter::Question objects.



44
45
46
47
48
# File 'lib/reporter/dump.rb', line 44

def questions
  @questions ||= data["questions"].map do |question_data|
    Record::Question.factory question_data
  end
end

#snapshotsObject

Public: Retrieves the list of snapshots in the Reporter dump.

Returns an Array of Reporter::Record::Response::Base objects.



53
54
55
56
57
# File 'lib/reporter/dump.rb', line 53

def snapshots
  @snapshots ||= data["snapshots"].map do |snapshot_data|
    Record::Snapshot.new snapshot_data
  end
end