Class: Reporter::Record::Snapshot

Inherits:
Base
  • Object
show all
Defined in:
lib/reporter/record/snapshot.rb

Overview

Public: Represents an individual “report” made using Reporter.

Instance Method Summary collapse

Methods inherited from Base

#==, #hash, #initialize

Constructor Details

This class inherits a constructor from Reporter::Record::Base

Instance Method Details

#audioObject

Public: Retrieves the audio record for this snapshot.


13
14
15
# File 'lib/reporter/record/snapshot.rb', line 13

def audio
  @audio ||= Record::Audio.new @data["audio"]
end

#backgroundObject

Public: A state variable indicating the report was captured in

the background.

We are note captuing reports in the background. Therefore, this attribute is not in use.


22
23
24
# File 'lib/reporter/record/snapshot.rb', line 22

def background
  @background ||= @data["background"]
end

#batteryObject

Public: Retrieves the level of power stored in the iPhone's

battery at the time of this report.

Returns a double numerical value, between 0 and 1, reflecting the

power stored in the iPhone's battery at the time of this
report.

32
33
34
# File 'lib/reporter/record/snapshot.rb', line 32

def battery
  @battery ||= @data["battery"].to_f
end

#connectionObject

Public: Indicates the current network connection of the device.

Its value corresponds to the following states:

0: Device is connected via cellular network
1: Device is connected via WiFi
2: Device is not connected

Returns one of the above integers.


45
46
47
# File 'lib/reporter/record/snapshot.rb', line 45

def connection
  @connection ||= @data["connection"].to_i
end

#dateObject

Public: Represents when the snapshot was created.

Returns a DateTime representing the date of the snapshot.


52
53
54
# File 'lib/reporter/record/snapshot.rb', line 52

def date
  @date ||= DateTime.iso8601 @data["date"]
end

#draftObject

Public: A state variable indicating the report is being edited.

If it is, it won't be saved. Therefore, this will always be 0.


59
60
61
# File 'lib/reporter/record/snapshot.rb', line 59

def draft
  @draft ||= @data["draft"]
end

#dwell_statusObject

Public: Debug variable. Not in use.


64
65
66
# File 'lib/reporter/record/snapshot.rb', line 64

def dwell_status
  @dwell_status ||= @data["dwellStatus"]
end

#locationObject

Public: Retrieves the Location record for this report.


69
70
71
# File 'lib/reporter/record/snapshot.rb', line 69

def location
  @location ||= Record::Location.new @data["location"]
end

#report_impetusObject

Public: Indicates how the report was triggered.

The value for this attribute cooresponds to the following events:

0: Report button tapped
1: Report button tapped while Reporter is asleep
2: Report triggered by notification
3: Report triggered by setting app to sleep
4: Report triggered by waking up app

Returns one of the above integers.


84
85
86
# File 'lib/reporter/record/snapshot.rb', line 84

def report_impetus
  @report_impetus ||= @data["reportImpetus"].to_i
end

#responsesObject

Public: Retrieves the responses to the Reporter survey questions

in this report, containing any information entered by the user.

Returns an Array of Response objects.


92
93
94
95
96
# File 'lib/reporter/record/snapshot.rb', line 92

def responses
  @responses ||= @data["responses"].map do |response_data|
    Record::Response.factory response_data
  end
end

#section_identifierObject

Public: A convenience variable used by the application when

displaying reports in a UITableView.

Returns the String value as-is.


102
103
104
# File 'lib/reporter/record/snapshot.rb', line 102

def section_identifier
  @section_identifier ||= @data["sectionIdentifier"].to_s
end

#stepsObject

Public: Retrieves the number of steps taken between the last

report filed and this report.

It is only captured if the user is using an iPhone 5S, which features the M7 motion coprocessor. We at Reporter Inc have decided not to capture steps on other devices because implementing background step-counting without the M7 is non-trivial and tends to burn battery if you're not careful (read: invest many hours in fine tuning your code for a variety of situations).

Returns a single numerical value reflecting the number of steps.


118
119
120
# File 'lib/reporter/record/snapshot.rb', line 118

def steps
  @steps ||= @data["steps"].to_i
end

#syncObject

Sync: This is a state variable to ensure each report is saved to

Dropbox.

It will always be 0 because once it is 1 (or true) the app will not attempt to write it to Dropbox.


127
128
129
# File 'lib/reporter/record/snapshot.rb', line 127

def sync
  @sync ||= @data["sync"]
end

#weatherObject

Public: Retrieves the Weather record for this report.


132
133
134
# File 'lib/reporter/record/snapshot.rb', line 132

def weather
  @weather ||= Record::Weather.new @data["weather"]
end