Module: SplitIoClient::Utilities
Instance Method Summary collapse
- #randomize_interval(interval) ⇒ Object
- #split_bulk_to_send(hash, divisions) ⇒ Object
-
#to_epoch(value) ⇒ Object
Convert String with Time info to its epoch FixNum previously setting to zero the seconds.
- #to_epoch_milis(value) ⇒ Object
- #to_milis_zero_out_from_hour(value) ⇒ Object
- #to_milis_zero_out_from_seconds(value) ⇒ Object
Instance Method Details
#randomize_interval(interval) ⇒ Object
35 36 37 38 39 |
# File 'lib/splitclient-rb/utilitites.rb', line 35 def randomize_interval(interval) random_factor = Random.new.rand(50..100) / 100.0 interval * random_factor end |
#split_bulk_to_send(hash, divisions) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/splitclient-rb/utilitites.rb', line 41 def split_bulk_to_send(hash, divisions) count = 0 hash.each_with_object([]) do |key_value, final| final[count % divisions] ||= {} final[count % divisions][key_value[0]] = key_value[1] count += 1 end rescue StandardError [] end |
#to_epoch(value) ⇒ Object
Convert String with Time info to its epoch FixNum previously setting to zero the seconds
6 7 8 9 10 11 |
# File 'lib/splitclient-rb/utilitites.rb', line 6 def to_epoch(value) parsed = Time.parse(value) zeroed = Time.new(parsed.year, parsed.month, parsed.day, parsed.hour, parsed.min, 0, 0) zeroed.to_i end |
#to_epoch_milis(value) ⇒ Object
13 14 15 |
# File 'lib/splitclient-rb/utilitites.rb', line 13 def to_epoch_milis(value) to_epoch(value) * 1000 end |
#to_milis_zero_out_from_hour(value) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/splitclient-rb/utilitites.rb', line 26 def to_milis_zero_out_from_hour(value) parsed_value = Time.strptime(value.to_s, '%s').utc zeroed = Time.new(parsed_value.year, parsed_value.month, parsed_value.day, 0, 0, 0, 0) zeroed.to_i * 1000 rescue StandardError return :non_valid_date_info end |
#to_milis_zero_out_from_seconds(value) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/splitclient-rb/utilitites.rb', line 17 def to_milis_zero_out_from_seconds(value) parsed_value = Time.strptime(value.to_s, '%s').utc zeroed = Time.new(parsed_value.year, parsed_value.month, parsed_value.day, parsed_value.hour, parsed_value.min, 0, 0) zeroed.to_i * 1000 rescue StandardError return :non_valid_date_info end |