Class: Hyrax::Ingest::Reporting::Report
- Inherits:
-
Object
- Object
- Hyrax::Ingest::Reporting::Report
- Defined in:
- lib/hyrax/ingest/reporting/report.rb
Instance Attribute Summary collapse
-
#stat ⇒ Object
readonly
Returns the value of attribute stat.
Instance Method Summary collapse
- #default_stat ⇒ Object
- #errors ⇒ Object
- #failed? ⇒ Boolean
- #failed_with(error) ⇒ Object
-
#initialize ⇒ Report
constructor
A new instance of Report.
- #render(template_path: nil) ⇒ Object
- #write_to_file(filename: nil, template_path: nil) ⇒ Object
Constructor Details
#initialize ⇒ Report
Returns a new instance of Report.
11 12 13 |
# File 'lib/hyrax/ingest/reporting/report.rb', line 11 def initialize @stat = default_stat end |
Instance Attribute Details
#stat ⇒ Object (readonly)
Returns the value of attribute stat.
9 10 11 |
# File 'lib/hyrax/ingest/reporting/report.rb', line 9 def stat @stat end |
Instance Method Details
#default_stat ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hyrax/ingest/reporting/report.rb', line 15 def default_stat # Initialize a FunctionalHash to serve as a stat tracker, and # add some default values in the same way you would a Hash. @stat = FunctionalHash.new.tap do |stat| # Stores an array of all SIP paths. stat[:sip_paths] = [] # Stores a list of all files from SIPs that are part of the ingest. stat[:files] = [] # Stores a hash where keys are Fetcher classes, and values are # the number of occurrences of missing rquired values. stat[:missing_required_values] = {} stat[:total_missing_required_values] = Proc.new do |s| stat[:missing_required_values].reduce(0) do |total, key_and_value| # When reducing a Hash, the 2nd arg to the block is a # 2-element array, where the 1st element is the key, and the # 2nd element is the value the key points to. occurrences = key_and_value.last total + occurrences.count end end # Filters the :missing_required_values hash to those for XML files. # stat[:xml_files_missing_required_values] = Proc.new do |s| # s[:missing_required_values].select { |fetcher_class, params| fetcher_class.to_s =~ /XMLFile$/ } # end # Define a functional hash value that returns the count of the given key. stat[:count] = Proc.new do |s, key_to_count| s[key_to_count].respond_to?(:count) ? s[key_to_count].count : 0 end stat[:models_saved] = [] stat[:models_failed] = [] end end |
#errors ⇒ Object
69 70 71 |
# File 'lib/hyrax/ingest/reporting/report.rb', line 69 def errors @errors ||= [] end |
#failed? ⇒ Boolean
73 74 75 |
# File 'lib/hyrax/ingest/reporting/report.rb', line 73 def failed? !errors.empty? end |
#failed_with(error) ⇒ Object
65 66 67 |
# File 'lib/hyrax/ingest/reporting/report.rb', line 65 def failed_with(error) errors << error end |