Skip to content

Instantly share code, notes, and snippets.

@gingray
Created July 15, 2021 08:35
Show Gist options
  • Save gingray/7ac187a392fe6753ac063d7380b6cc6d to your computer and use it in GitHub Desktop.
Save gingray/7ac187a392fe6753ac063d7380b6cc6d to your computer and use it in GitHub Desktop.
chatmorgul
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