Class: Common
- Inherits:
-
Object
- Object
- Common
- Defined in:
- lib/artemo/common.rb
Overview
Note:
This class have all common classes for all program
Returns of scaled emotions in range 0..100.
Direct Known Subclasses
Class Method Summary collapse
Class Method Details
.check(array_one) ⇒ Object
Note:
This method is checking which value is greater, if it’s greater then it is true.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/artemo/common.rb', line 18 def self.check(array_one) values_array = Array.new(array_one.size).fill(0) array_one.each_index do |index| next if index.odd? difference = array_one[index] - array_one[index + 1] if difference >= 0 values_array[index] = true values_array[index + 1] = false else values_array[index] = false values_array[index + 1] = true end end values_array end |
.scale(array_one) ⇒ Object
Note:
This method is scaling values in range min..100
7 8 9 10 11 12 13 14 |
# File 'lib/artemo/common.rb', line 7 def self.scale(array_one) min, max = array_one.minmax to_min = ((min.to_f / max.to_f) * 100.0).floor.to_f array_one.each_index do |index| array_one[index] = ((100.0 - to_min) * (array_one[index] - min).to_f / (max - min).to_f + to_min).to_i end array_one end |
.weigh(array_one, array_two) ⇒ Object
Note:
This method check which value is true and if it’s true add two, else add one.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/artemo/common.rb', line 37 def self.weigh(array_one, array_two) weighed_array = Array.new(array_one).fill(50) array_one.each_index do |index| 50.times do if array_two[index] weighed_array[index] += 1.25 if array_one[index] >= 75 weighed_array[index] += 1.0 if array_one[index] < 75 && array_one[index] >= 50 else weighed_array[index] -= 1.0 if array_one[index] < 50 && array_one[index] >= 25 weighed_array[index] -= 1.25 if array_one[index] < 25 end end end array_one.each_index do |index| if weighed_array[index] >= 0 weighed_array[index] = weighed_array[index].to_i else weighed_array[index] = 0 end end weighed_array end |