Created
July 15, 2021 08:35
-
-
Save gingray/7ac187a392fe6753ac063d7380b6cc6d to your computer and use it in GitHub Desktop.
chatmorgul
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'set' | |
require 'date' | |
class Event | |
attr_reader :event_name, :date | |
def initialize(event_name, date) | |
@event_name = event_name | |
@date = date | |
end | |
def self.parse(hash) | |
new(hash['event'], ::Date.parse(hash['date'])) | |
end | |
def <=>(other) | |
date <=> other.date | |
end | |
def eql?(other) | |
event_name == other.event_name && date == other.date | |
end | |
end | |
items = JSON.parse(File.read('./events.json')) | |
events = items.each_with_object({}) do |item, hash| | |
key = item['account'] | |
unless hash.key?(key) | |
hash[key] = SortedSet.new | |
end | |
evt = Event.parse(item) | |
hash[key] << evt | |
end | |
lookup_date = Date.parse('April 2nd, 2020') | |
events.each do |key, val| | |
if val.select { |evt| evt.date < lookup_date }.last.event_name != 'cancellation' | |
puts "account #{key} has active subscription on #{lookup_date}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment