From a80c46c5c9678bdcf6924309724cceec6b928853 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Mon, 23 Feb 2015 21:28:41 +0100 Subject: [PATCH] Create a base class for weighting This class should contain methods, which are used in more than one weighting class. At the moment it contains the bucket handling. --- lib/rubella/weighting/base.rb | 57 ++++++++++++++++++++++++++++++ lib/rubella/weighting/per_value.rb | 38 +++----------------- 2 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 lib/rubella/weighting/base.rb diff --git a/lib/rubella/weighting/base.rb b/lib/rubella/weighting/base.rb new file mode 100644 index 0000000..4e04005 --- /dev/null +++ b/lib/rubella/weighting/base.rb @@ -0,0 +1,57 @@ +module Rubella + module Weighting + + + # The Rubella::Weighting object processes the given input data to an valid + # output processable Array. + # These arrays contain a subarray for every unit of time. And these Array + # contain the buckets within the values for the output objects. + # The Weighting of the print intensitiy is done here, so that the output + # objects job is simply to print the stuff. + # + class Base + attr_reader :buckets + # :steps + + # Constructor + # Creates a new Rubella::Weighting::xy object. + # + # @param buckets int must be one of 1, 2, 5, 10, 20, 50 default is 10 + # @return Rubella::Weighting::PerValue + # @raise ArgumentError + # + def initialize(buckets = 10) + self.buckets = buckets + end + + # Sets the buckets, if the value is valid + # + # @param buckets int The amount of buckets + # @raise ArgumentError + # + def buckets= buckets + # Must be divideable by 100 + if([1, 2, 5, 10, 20, 50].index(buckets) == nil) + raise ArgumentError, "Amount of buckets must be 1, 2, 5, 10, 20 or 50" + end + + @steps = 100/buckets + @buckets = buckets + end + + # Creates a output readable list. + # This list is Array within a subarrays, which contain the buckets for + # every time value unit. + # + # @param input Rubella::Input An input object + # @return Array + # + def parse input + raise NotImplementedError "Please override 'parse' in your concrete "+ + "implementation" + end + + end + + end +end diff --git a/lib/rubella/weighting/per_value.rb b/lib/rubella/weighting/per_value.rb index abe4f2a..a86023c 100644 --- a/lib/rubella/weighting/per_value.rb +++ b/lib/rubella/weighting/per_value.rb @@ -1,30 +1,14 @@ +require "rubella/weighting/base" + module Rubella module Weighting - # The Rubella::Weighting object processes the given input data to an valid - # output processable Array. - # These arrays contain a subarray for every unit of time. And these Array - # contain the buckets within the values for the output objects. - # The Weighting of the print intensitiy is done here, so that the output - # objects job is simply to print the stuff. - # # The Rubella::Weighting::PerValue object weights every bucket set to 1 in # ammount. So if you have have for example four cores, every core is # weighted to 0.25 no matter how much the load of a single core is. It's # just a "as is" weighting. - class PerValue - attr_reader :buckets - # :steps - - # Constructor - # Creates a new Rubella::Weighting::PerValue object. - # - # @param buckets int must be one of 1, 2, 5, 10, 20, 50 default is 10 - # @return Rubella::Weighting::PerValue - # @raise ArgumentError - def initialize(buckets = 10) - self.buckets = buckets - end + # + class PerValue < Base # Creates a output readable list. # This list is Array within a subarrays, which contain the buckets for @@ -57,20 +41,6 @@ module Rubella data_list end - # Sets the buckets, if the value is valid - # - # @param buckets int The amount of buckets - # @raise ArgumentError - def buckets= buckets - # Must be divideable by 100 - if([1, 2, 5, 10, 20, 50].index(buckets) == nil) - raise ArgumentError, "Amount of buckets must be 1, 2, 5, 10, 20 or 50" - end - - @steps = 100/buckets - @buckets = buckets - end - end end