Class: Cuboid::Report
- Includes:
- Utilities
- Defined in:
- lib/cuboid/report.rb
Overview
Constant Summary collapse
- EXTENSION =
'crf'
- INTEGER_SIZE =
4
- UNPACK =
'N'
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#data ⇒ Object
Arbitrary data from the Application.
-
#finish_datetime ⇒ Time
The date and time when the scan finished.
- #options ⇒ Hash
-
#seed ⇒ String
Scan seed.
-
#start_datetime ⇒ Time
The date and time when the scan started.
- #status ⇒ Symbol
- #version ⇒ String
Class Method Summary collapse
- .from_crf(data) ⇒ Object
- .from_rpc_data(data) ⇒ DOM
- .load(file) ⇒ Report
-
.read_summary(report) ⇒ Hash
#summary associated with the given report.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#delta_time ⇒ String
‘#start_datetime - #finish_datetime` in `00:00:00` (`hours:minutes:seconds`) format.
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Report
constructor
A new instance of Report.
-
#save(location = nil) ⇒ String
Absolute location of the report.
-
#summary ⇒ Hash
Summary data of the report.
-
#to_crf ⇒ String
Report serialized in the Cuboid Report format.
-
#to_h ⇒ Hash
(also: #to_hash)
Hash representation of ‘self`.
-
#to_rpc_data ⇒ Hash
Data representing this instance that are suitable the RPC transmission.
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
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 |
#data ⇒ Object
Arbitrary data from the Application.
34 35 36 |
# File 'lib/cuboid/report.rb', line 34 def data @data end |
#finish_datetime ⇒ Time
Returns The date and time when the scan finished.
42 43 44 |
# File 'lib/cuboid/report.rb', line 42 def finish_datetime @finish_datetime end |
#options ⇒ Hash
Returns Options#to_h.
31 32 33 |
# File 'lib/cuboid/report.rb', line 31 def @options end |
#seed ⇒ String
Returns Scan seed.
27 28 29 |
# File 'lib/cuboid/report.rb', line 27 def seed @seed end |
#start_datetime ⇒ Time
Returns The date and time when the scan started.
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
Returns VERSION.
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
Loads and a saved Cuboid::Report object from file.
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
Returns #summary associated with the given report.
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
If no #finish_datetime has been provided, it will use ‘Time.now`.
Returns ‘#start_datetime - #finish_datetime` in `00:00:00` (`hours:minutes:seconds`) format.
58 59 60 |
# File 'lib/cuboid/report.rb', line 58 def delta_time seconds_to_hms( (@finish_datetime || Time.now) - @start_datetime ) end |
#hash ⇒ Object
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
Returns Absolute location of the report.
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 # We do it this way to prevent FS watchers from grabbing files that # are in the process of being written and thus partial. tmp = "#{Options.paths.tmpdir}/#{Utilities.generate_token}" IO.binwrite( tmp, to_crf ) FileUtils.mv tmp, location File.( location ) end |
#summary ⇒ Hash
Returns Summary data of the report.
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
Returns Report serialized in the Cuboid Report format.
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 # Append metadata to the end of the dump. = RPC::Serializer.dump( sum ) crf << [, .size].pack( "a*#{UNPACK}" ) crf end |
#to_h ⇒ Hash Also known as: to_hash
Returns Hash representation of ‘self`.
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
Returns Data representing this instance that are suitable the RPC transmission.
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 |