Class: Cuboid::Report
Overview
Constant Summary
collapse
- EXTENSION =
'crf'
- INTEGER_SIZE =
4
- UNPACK =
'N'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utilities
#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #exception_jail, #generate_token, #hms_to_seconds, #port_available?, #rand_port, #random_seed, #regexp_array_match, #remove_constants, #seconds_to_hms
Constructor Details
#initialize(options = {}) ⇒ Report
44
45
46
47
48
49
50
51
|
# File 'lib/cuboid/report.rb', line 44
def initialize( options = {} )
options.each { |k, v| send( "#{k}=", v ) }
@version ||= Cuboid::VERSION
@start_datetime ||= Time.now
@finish_datetime ||= Time.now
end
|
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
20
21
22
|
# File 'lib/cuboid/report.rb', line 20
def application
@application
end
|
Arbitrary data from the Application.
34
35
36
|
# File 'lib/cuboid/report.rb', line 34
def data
@data
end
|
#finish_datetime ⇒ Time
42
43
44
|
# File 'lib/cuboid/report.rb', line 42
def finish_datetime
@finish_datetime
end
|
#options ⇒ Hash
31
32
33
|
# File 'lib/cuboid/report.rb', line 31
def options
@options
end
|
#seed ⇒ String
27
28
29
|
# File 'lib/cuboid/report.rb', line 27
def seed
@seed
end
|
#start_datetime ⇒ Time
38
39
40
|
# File 'lib/cuboid/report.rb', line 38
def start_datetime
@start_datetime
end
|
#status ⇒ Symbol
23
24
25
|
# File 'lib/cuboid/report.rb', line 23
def status
@status
end
|
#version ⇒ String
18
19
20
|
# File 'lib/cuboid/report.rb', line 18
def version
@version
end
|
Class Method Details
.from_crf(data) ⇒ Object
127
128
129
130
131
|
# File 'lib/cuboid/report.rb', line 127
def self.from_crf( data )
from_rpc_data RPC::Serializer.load(
self.crf_without_summary( StringIO.new( data ) )
)
end
|
.from_rpc_data(data) ⇒ DOM
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/cuboid/report.rb', line 183
def self.from_rpc_data( data )
data['start_datetime'] = Time.parse( data['start_datetime'] )
data['finish_datetime'] = Time.parse( data['finish_datetime'] )
data['application'] = ObjectSpace.const_get( data['application'] )
data['data'] = data['application'].serializer.load( data['data'] )
data['options'] = data['application'].serializer.load( data['options'] )
new data
end
|
.load(file) ⇒ Report
86
87
88
89
90
|
# File 'lib/cuboid/report.rb', line 86
def self.load( file )
File.open( file, 'rb' ) do |f|
from_rpc_data RPC::Serializer.load( self.crf_without_summary( f ) )
end
end
|
.read_summary(report) ⇒ Hash
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/cuboid/report.rb', line 67
def self.read_summary( report )
File.open( report ) do |f|
f.seek -INTEGER_SIZE, IO::SEEK_END
summary_size = f.read( INTEGER_SIZE ).unpack( 'N' ).first
f.seek -summary_size-INTEGER_SIZE, IO::SEEK_END
summary = RPC::Serializer.load( f.read( summary_size ) ).my_symbolize_keys
summary[:application] = ObjectSpace.const_get( summary[:application].to_sym )
summary
end
end
|
Instance Method Details
#==(other) ⇒ Object
194
195
196
|
# File 'lib/cuboid/report.rb', line 194
def ==( other )
hash == other.hash
end
|
#delta_time ⇒ String
58
59
60
|
# File 'lib/cuboid/report.rb', line 58
def delta_time
seconds_to_hms( (@finish_datetime || Time.now) - @start_datetime )
end
|
198
199
200
201
202
203
204
|
# File 'lib/cuboid/report.rb', line 198
def hash
h = to_hash
[:start_datetime, :finish_datetime, :delta_datetime].each do |k|
h.delete k
end
h.hash
end
|
#save(location = nil) ⇒ String
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/cuboid/report.rb', line 97
def save( location = nil )
if !location
location = default_filename
elsif File.directory? location
location += "/#{default_filename}"
end
tmp = "#{Options.paths.tmpdir}/#{Utilities.generate_token}"
IO.binwrite( tmp, to_crf )
FileUtils.mv tmp, location
File.expand_path( location )
end
|
#summary ⇒ Hash
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/cuboid/report.rb', line 152
def summary
{
application: @application,
version: @version,
status: @status,
seed: @seed,
start_datetime: @start_datetime.to_s,
finish_datetime: @finish_datetime.to_s,
delta_time: delta_time
}
end
|
#to_crf ⇒ String
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/cuboid/report.rb', line 115
def to_crf
crf = RPC::Serializer.dump( self )
sum = summary
sum[:application] = sum[:application].to_s
metadata = RPC::Serializer.dump( sum )
crf << [metadata, metadata.size].pack( "a*#{UNPACK}" )
crf
end
|
#to_h ⇒ Hash
Also known as:
to_hash
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/cuboid/report.rb', line 135
def to_h
h = {
application: @application,
version: @version,
status: @status,
seed: @seed,
data: @data,
options: Cuboid::Options.hash_to_rpc_data( @options ),
start_datetime: @start_datetime.to_s,
finish_datetime: @finish_datetime.to_s,
delta_time: delta_time
}
end
|
#to_rpc_data ⇒ Hash
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/cuboid/report.rb', line 166
def to_rpc_data
data = {}
instance_variables.each do |ivar|
data[ivar.to_s.gsub('@','')] = instance_variable_get( ivar )
end
data['application'] = data['application'].to_s
data['data'] = @application.serializer.dump( data['data'] )
data['options'] = @application.serializer.dump( data['options'] )
data['start_datetime'] = data['start_datetime'].to_s
data['finish_datetime'] = data['finish_datetime'].to_s
data
end
|