class PulseAnalysis::Report
Attributes
analysis[R]
items[R]
Public Class Methods
new(analysis)
click to toggle source
@param [PulseAnalysis::Analysis] analysis The analysis to report on. Required that analysis has been run (see Analysis#run
)
# File lib/pulse-analysis/report.rb, line 8 def initialize(analysis) @analysis = analysis populate_items end
Public Instance Methods
inspect()
click to toggle source
Override Object#inspect to not include the large audio data @return [String]
# File lib/pulse-analysis/report.rb, line 26 def inspect to_h.inspect end
to_h()
click to toggle source
Convert the report to a hash @return [Hash]
# File lib/pulse-analysis/report.rb, line 15 def to_h { file: { path: @analysis.sound.audio_file.path.to_s }, analysis: @items } end
Private Instance Methods
length_in_formatted_time()
click to toggle source
Usable length of the audio file in the format (MMmSSs) @return [String]
# File lib/pulse-analysis/report.rb, line 34 def length_in_formatted_time @length_in_formatted_time ||= Conversion.num_samples_to_formatted_time(@analysis.sound.sample_rate, @analysis.sound.size) end
populate_items()
click to toggle source
Popualate the report @return [Array]
# File lib/pulse-analysis/report.rb, line 40 def populate_items if @analysis.periods.nil? raise "Analysis has not been run yet (use Analysis#run)" else @items = [] @items << { key: :sample_rate, description: "Sample rate", value: { unit: "Hertz", value: @analysis.sound.sample_rate } } @items << { key: :length, description: "Length", value: [ { unit: "Number of pulses", value: @analysis.num_pulses }, { unit: "Time", value: length_in_formatted_time } ] } @items << { key: :tempo, description: "Tempo", value: { unit: "BPM", value: @analysis.tempo_bpm.round(4) } } @items << { key: :longest_period, description: "Longest period length", value: [ { unit: "Samples", value: @analysis.longest_period }, { unit: "ms", value: Conversion.num_samples_to_millis(@analysis.sound.sample_rate, @analysis.longest_period).round(2) } ] } @items << { key: :shortest_period, description: "Shortest period length", value: [ { unit: "Samples", value: @analysis.shortest_period }, { unit: "ms", value: Conversion.num_samples_to_millis(@analysis.sound.sample_rate, @analysis.shortest_period).round(2) } ] } @items << { key: :average_period, description: "Average period length", value: [ { unit: "Samples", value: @analysis.average_period.round(4) }, { unit: "ms", value: Conversion.num_samples_to_millis(@analysis.sound.sample_rate, @analysis.average_period).round(2) } ] } @items << { key: :largest_abberation, description: "Largest abberation", value: [ { unit: "Samples", value: @analysis.largest_abberation }, { unit: "ms", value: Conversion.num_samples_to_millis(@analysis.sound.sample_rate, @analysis.largest_abberation).round(2) } ] } @items << { key: :average_abberation, description: "Average abberation", value: [ { unit: "Samples", value: @analysis.average_abberation.round(4) }, { unit: "ms", value: Conversion.num_samples_to_millis(@analysis.sound.sample_rate, @analysis.average_abberation).round(2) } ] } @items end end