Sha256: ea1bd4ed0f2ff2b9f7ea0da1d7f751fbf0923c71732311f97b45c1ee771aeea8
Contents?: true
Size: 755 Bytes
Versions: 4
Compression:
Stored size: 755 Bytes
Contents
# frozen_string_literal: true class Hash def to_key_indexed_array(min_size: 0, default: nil) raise ArgumentError, 'all the keys must be numbers to convert to key indexed array' unless all? { |k, _v| k.is_a? Numeric } each_with_object(Array.new(min_size, default)) { |(k, v), acc| acc[k] = v }.map { |e| e || default } end def fill_empty_days!(aggregated: true) return self if empty? self_with_date_keys = transform_keys(&:to_date) days_with_data = self_with_date_keys.keys.sort.uniq prev = 0 days_with_data.first.upto(days_with_data.last) do |day| if days_with_data.include?(day) prev = self_with_date_keys[day] else self[day] = aggregated ? prev : 0 end end self end end
Version data entries
4 entries across 4 versions & 1 rubygems