Class: IMW::Tools::Summarizer
- Inherits:
-
Object
- Object
- IMW::Tools::Summarizer
- Includes:
- ExtensionAnalyzer
- Defined in:
- lib/imw/tools/summarizer.rb
Overview
A class for producing summary data about a collection of resources.
The Summarizer needs recursively IMW.open all files and directories given so will be very cumbersome if given many files. Few large files will not cause a problem.
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
The inputs given to this Summarizer.
-
#options ⇒ Object
Options for this Summarizer.
-
#resources ⇒ Object
readonly
The resources analyzed, calculated recursively from the
inputs.
Instance Method Summary collapse
-
#initialize(*inputs) ⇒ IMW::Tools::Summarizer
constructor
Initialize a new Summarizer with the given
inputs. -
#summary ⇒ Array<Hash>
Return a summary of the
inputsto this Summarizer. -
#summary! ⇒ Array
Return a summary of the
inputsto this summarizer. -
#total_size ⇒ Integer
Return the total size of all resources.
Methods included from ExtensionAnalyzer
#extension_counts, #extension_sizes, #most_common_data_format, #most_common_extension, #most_common_extension_by_count, #most_common_extension_by_size, #normalized_extension_counts, #normalized_extension_sizes
Constructor Details
#initialize(*inputs) ⇒ IMW::Tools::Summarizer
Initialize a new Summarizer with the given inputs.
A Hash of options can be given as the last parameter.
32 33 34 35 |
# File 'lib/imw/tools/summarizer.rb', line 32 def initialize *inputs self. = (inputs.last.is_a?(Hash) && inputs.pop) || {} self.inputs = inputs.flatten end |
Instance Attribute Details
#inputs ⇒ Object
The inputs given to this Summarizer.
18 19 20 |
# File 'lib/imw/tools/summarizer.rb', line 18 def inputs @inputs end |
#options ⇒ Object
Options for this Summarizer.
15 16 17 |
# File 'lib/imw/tools/summarizer.rb', line 15 def end |
#resources ⇒ Object (readonly)
The resources analyzed, calculated recursively from the inputs.
22 23 24 |
# File 'lib/imw/tools/summarizer.rb', line 22 def resources @resources end |
Instance Method Details
#summary ⇒ Array<Hash>
Return a summary of the inputs to this Summarizer.
Will swallow errors.
49 50 51 |
# File 'lib/imw/tools/summarizer.rb', line 49 def summary @summary ||= summary! rescue [] end |
#summary! ⇒ Array
Return a summary of the inputs to this summarizer.
Delegates to the summary method of each constituent IMW::Resource in inputs.
59 60 61 62 63 |
# File 'lib/imw/tools/summarizer.rb', line 59 def summary! inputs.map do |input| (input.respond_to?(:summary) ? input.summary : {}) end end |
#total_size ⇒ Integer
Return the total size of all resources.
40 41 42 |
# File 'lib/imw/tools/summarizer.rb', line 40 def total_size @total_size ||= resources.map(&:size).inject(0) { |e, sum| sum += e } end |