Class: RSlog::DataProcessing
- Inherits:
-
Object
- Object
- RSlog::DataProcessing
- Defined in:
- lib/rslog/data_processing.rb
Overview
Class to hold data_processing methods
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#calculate ⇒ Object
calculate.
-
#extract ⇒ Object
extract.
-
#group ⇒ Object
group.
-
#initialize(source, conf) ⇒ DataProcessing
constructor
A new instance of DataProcessing.
-
#order ⇒ Object
sort.
Constructor Details
#initialize(source, conf) ⇒ DataProcessing
Returns a new instance of DataProcessing.
9 10 11 12 13 |
# File 'lib/rslog/data_processing.rb', line 9 def initialize(source, conf) @calc = conf.fetch(:calc) { proc } @separator = conf.fetch(:separator, ' ') @result = Array(source) end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/rslog/data_processing.rb', line 7 def result @result end |
Instance Method Details
#calculate ⇒ Object
calculate
28 29 30 31 32 33 34 |
# File 'lib/rslog/data_processing.rb', line 28 def calculate # calculate visits @result = @result.map { |url, visits| [url, @calc.call(visits)] } # calculate average # @result = @result.map { |url, visits_qty| [url, visits_qty, (visits_qty.to_f / _total)] } self end |
#extract ⇒ Object
extract
16 17 18 19 |
# File 'lib/rslog/data_processing.rb', line 16 def extract @result = @result.map { |item| item.split(@separator) } self end |
#group ⇒ Object
group
22 23 24 25 |
# File 'lib/rslog/data_processing.rb', line 22 def group @result = @result.group_by { |url, _visits| url }.to_a self end |
#order ⇒ Object
sort
37 38 39 40 41 |
# File 'lib/rslog/data_processing.rb', line 37 def order @result = @result.sort_by { |_url, visits_by_page| visits_by_page } @result.reverse! self end |