active_object 5.8.0 → 5.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/active_object/enumerable.rb +11 -18
 - data/lib/active_object/hash.rb +1 -2
 - data/lib/active_object/integer.rb +1 -1
 - data/lib/active_object/numeric.rb +10 -4
 - data/lib/active_object/string.rb +1 -3
 - data/lib/active_object/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f6749777a782c78d352dff3fd8ea2ee047924a64e589c05377ebc9610eee5e34
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3f8059fa849376bcd053182e61238c7d75b074c47822f2844b2ee74aebdcafbf
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f941a7ff54a3b52614b07ff3bb9ba8b7774761c1415ccca33b97b5bb08bc51b36a9c51ce9b0399a818852ea54337a13da8658418d5a5d312c715aac9dde7e850
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1bf88511a3c768cef14edebdc2010d886c90eec0dbf6e45fc441d6f61a9dcf20b5929df8af5a677c64f750edfa712f9df4f4b21e5d64b758fa082825a1f48516
         
     | 
| 
         @@ -192,16 +192,13 @@ if ActiveObject.configuration.autoload_enumerable 
     | 
|
| 
       192 
192 
     | 
    
         
             
                def median(identity = 0)
         
     | 
| 
       193 
193 
     | 
    
         
             
                  collection_length = length.to_f
         
     | 
| 
       194 
194 
     | 
    
         
             
                  collection_sorted = sort
         
     | 
| 
       195 
     | 
    
         
            -
                  return 
     | 
| 
      
 195 
     | 
    
         
            +
                  return identity unless collection_length > 0.0
         
     | 
| 
       196 
196 
     | 
    
         | 
| 
       197 
197 
     | 
    
         
             
                  half_collection = collection_length / 2.0
         
     | 
| 
       198 
198 
     | 
    
         
             
                  sorted_collection = collection_sorted[half_collection]
         
     | 
| 
      
 199 
     | 
    
         
            +
                  return sorted_collection unless (collection_length % 2).zero?
         
     | 
| 
       199 
200 
     | 
    
         | 
| 
       200 
     | 
    
         
            -
                   
     | 
| 
       201 
     | 
    
         
            -
                    (collection_sorted[half_collection - 1.0] + sorted_collection) / 2.0
         
     | 
| 
       202 
     | 
    
         
            -
                  else
         
     | 
| 
       203 
     | 
    
         
            -
                    sorted_collection
         
     | 
| 
       204 
     | 
    
         
            -
                  end
         
     | 
| 
      
 201 
     | 
    
         
            +
                  (collection_sorted[half_collection - 1.0] + sorted_collection) / 2.0
         
     | 
| 
       205 
202 
     | 
    
         
             
                end
         
     | 
| 
       206 
203 
     | 
    
         | 
| 
       207 
204 
     | 
    
         
             
                # rubocop:disable Metrics/AbcSize
         
     | 
| 
         @@ -229,24 +226,20 @@ if ActiveObject.configuration.autoload_enumerable 
     | 
|
| 
       229 
226 
     | 
    
         
             
                  each_with_object(::Hash.new(0)) { |key, hsh| hsh[key] += 1 }
         
     | 
| 
       230 
227 
     | 
    
         
             
                end
         
     | 
| 
       231 
228 
     | 
    
         | 
| 
       232 
     | 
    
         
            -
                # rubocop:disable Metrics/AbcSize 
     | 
| 
      
 229 
     | 
    
         
            +
                # rubocop:disable Metrics/AbcSize
         
     | 
| 
       233 
230 
     | 
    
         
             
                def percentile(num, identity = 0)
         
     | 
| 
       234 
231 
     | 
    
         
             
                  return identity unless length.positive?
         
     | 
| 
       235 
232 
     | 
    
         | 
| 
       236 
233 
     | 
    
         
             
                  collection_sorted = sort
         
     | 
| 
       237 
234 
     | 
    
         
             
                  rank = (num.to_f / 100) * (length + 1)
         
     | 
| 
      
 235 
     | 
    
         
            +
                  return collection_sorted[rank - 1] unless rank.fraction?
         
     | 
| 
       238 
236 
     | 
    
         | 
| 
       239 
     | 
    
         
            -
                   
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
             
     | 
| 
       243 
     | 
    
         
            -
             
     | 
| 
       244 
     | 
    
         
            -
                    (rank.fraction * (sample_two - sample_one)) + sample_one
         
     | 
| 
       245 
     | 
    
         
            -
                  else
         
     | 
| 
       246 
     | 
    
         
            -
                    collection_sorted[rank - 1]
         
     | 
| 
       247 
     | 
    
         
            -
                  end
         
     | 
| 
      
 237 
     | 
    
         
            +
                  truncated_rank = rank.truncate
         
     | 
| 
      
 238 
     | 
    
         
            +
                  sample_one = collection_sorted[truncated_rank - 1]
         
     | 
| 
      
 239 
     | 
    
         
            +
                  sample_two = collection_sorted[truncated_rank]
         
     | 
| 
      
 240 
     | 
    
         
            +
                  (rank.fraction * (sample_two - sample_one)) + sample_one
         
     | 
| 
       248 
241 
     | 
    
         
             
                end
         
     | 
| 
       249 
     | 
    
         
            -
                # rubocop:enable Metrics/AbcSize 
     | 
| 
      
 242 
     | 
    
         
            +
                # rubocop:enable Metrics/AbcSize
         
     | 
| 
       250 
243 
     | 
    
         | 
| 
       251 
244 
     | 
    
         
             
                def range(identity = 0)
         
     | 
| 
       252 
245 
     | 
    
         
             
                  return identity unless length.positive?
         
     | 
| 
         @@ -305,7 +298,7 @@ if ActiveObject.configuration.autoload_enumerable 
     | 
|
| 
       305 
298 
     | 
    
         
             
                end
         
     | 
| 
       306 
299 
     | 
    
         | 
| 
       307 
300 
     | 
    
         
             
                def take_last_if
         
     | 
| 
       308 
     | 
    
         
            -
                  return 
     | 
| 
      
 301 
     | 
    
         
            +
                  return to_enum(:take_last_if) unless block_given?
         
     | 
| 
       309 
302 
     | 
    
         | 
| 
       310 
303 
     | 
    
         
             
                  result = []
         
     | 
| 
       311 
304 
     | 
    
         
             
                  reverse_each { |val| yield(val) ? result.unshift(val) : break }
         
     | 
    
        data/lib/active_object/hash.rb
    CHANGED
    
    | 
         @@ -215,8 +215,7 @@ module ActiveObject 
     | 
|
| 
       215 
215 
     | 
    
         
             
                end
         
     | 
| 
       216 
216 
     | 
    
         | 
| 
       217 
217 
     | 
    
         
             
                def slice(*keys)
         
     | 
| 
       218 
     | 
    
         
            -
                  keys.flatten
         
     | 
| 
       219 
     | 
    
         
            -
                      .each_with_object({}) { |key, hsh| hsh[key] = self[key] if key?(key) }
         
     | 
| 
      
 218 
     | 
    
         
            +
                  keys.flatten.each_with_object({}) { |key, hsh| hsh[key] = self[key] if key?(key) }
         
     | 
| 
       220 
219 
     | 
    
         
             
                end
         
     | 
| 
       221 
220 
     | 
    
         | 
| 
       222 
221 
     | 
    
         
             
                def slice!(*keys)
         
     | 
| 
         @@ -32,7 +32,7 @@ module ActiveObject 
     | 
|
| 
       32 
32 
     | 
    
         
             
                  return '' if zero?
         
     | 
| 
       33 
33 
     | 
    
         
             
                  return "-#{(-self).roman}" if negative?
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                  ROMAN_VALUES.each { |key, val| return 
     | 
| 
      
 35 
     | 
    
         
            +
                  ROMAN_VALUES.each { |key, val| return "#{key}#{(self - val).roman}" if val <= self }
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                def time
         
     | 
| 
         @@ -313,7 +313,9 @@ module ActiveObject 
     | 
|
| 
       313 
313 
     | 
    
         
             
                end
         
     | 
| 
       314 
314 
     | 
    
         | 
| 
       315 
315 
     | 
    
         
             
                def multiple_of?(number)
         
     | 
| 
       316 
     | 
    
         
            -
                   
     | 
| 
      
 316 
     | 
    
         
            +
                  return zero? if number.zero?
         
     | 
| 
      
 317 
     | 
    
         
            +
             
     | 
| 
      
 318 
     | 
    
         
            +
                  modulo(number).zero?
         
     | 
| 
       317 
319 
     | 
    
         
             
                end
         
     | 
| 
       318 
320 
     | 
    
         | 
| 
       319 
321 
     | 
    
         
             
                def nautical_miles_in_inches
         
     | 
| 
         @@ -449,9 +451,9 @@ module ActiveObject 
     | 
|
| 
       449 
451 
     | 
    
         
             
                def to_length(from, to)
         
     | 
| 
       450 
452 
     | 
    
         
             
                  assert_inclusion_of_valid_keys!(LENGTH_KEYS.values.flatten, from, to)
         
     | 
| 
       451 
453 
     | 
    
         | 
| 
       452 
     | 
    
         
            -
                  metric_keys = LENGTH_KEYS.fetch(:metric)
         
     | 
| 
       453 
454 
     | 
    
         
             
                  return self if from == to
         
     | 
| 
       454 
455 
     | 
    
         | 
| 
      
 456 
     | 
    
         
            +
                  metric_keys = LENGTH_KEYS.fetch(:metric)
         
     | 
| 
       455 
457 
     | 
    
         
             
                  metrics_included_from = metric_keys.include?(from)
         
     | 
| 
       456 
458 
     | 
    
         | 
| 
       457 
459 
     | 
    
         
             
                  case to
         
     | 
| 
         @@ -475,9 +477,9 @@ module ActiveObject 
     | 
|
| 
       475 
477 
     | 
    
         
             
                def to_mass(from, to)
         
     | 
| 
       476 
478 
     | 
    
         
             
                  assert_inclusion_of_valid_keys!(MASS_KEYS.values.flatten, from, to)
         
     | 
| 
       477 
479 
     | 
    
         | 
| 
       478 
     | 
    
         
            -
                  metric_keys = MASS_KEYS.fetch(:metric)
         
     | 
| 
       479 
480 
     | 
    
         
             
                  return self if from == to
         
     | 
| 
       480 
481 
     | 
    
         | 
| 
      
 482 
     | 
    
         
            +
                  metric_keys = MASS_KEYS.fetch(:metric)
         
     | 
| 
       481 
483 
     | 
    
         
             
                  metrics_included_from = metric_keys.include?(from)
         
     | 
| 
       482 
484 
     | 
    
         | 
| 
       483 
485 
     | 
    
         
             
                  case to
         
     | 
| 
         @@ -562,7 +564,11 @@ module ActiveObject 
     | 
|
| 
       562 
564 
     | 
    
         
             
                  alpha = to_f
         
     | 
| 
       563 
565 
     | 
    
         
             
                  beta = number.to_f
         
     | 
| 
       564 
566 
     | 
    
         | 
| 
       565 
     | 
    
         
            -
                  alpha.zero? || beta.zero? 
     | 
| 
      
 567 
     | 
    
         
            +
                  if alpha.zero? || beta.zero?
         
     | 
| 
      
 568 
     | 
    
         
            +
                    (alpha - beta).abs < epsilon
         
     | 
| 
      
 569 
     | 
    
         
            +
                  else
         
     | 
| 
      
 570 
     | 
    
         
            +
                    (alpha / beta - 1).abs < epsilon
         
     | 
| 
      
 571 
     | 
    
         
            +
                  end
         
     | 
| 
       566 
572 
     | 
    
         
             
                end
         
     | 
| 
       567 
573 
     | 
    
         | 
| 
       568 
574 
     | 
    
         
             
                def yards_in_inches
         
     | 
    
        data/lib/active_object/string.rb
    CHANGED