-
-
Save eggie5/e6d46087596987ad480e to your computer and use it in GitHub Desktop.
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
#Databind model | |
u=User.new;u.id=1 | |
u.add_friend(10.days.ago,2) | |
u.add_friend(7.days.ago,3) | |
u.add_follower(6.days.ago, 4) | |
u.add_friend(6.days.ago, 23) | |
u.add_friend(6.days.ago, 33); | |
u.remove_friend(5.days.ago, 2) | |
................. | |
#query model | |
#get current friends and followers on twitter | |
friends = u.friends | |
followers = u.followers | |
#get friends at time in past | |
friends=u.friends(at: 30.days.ago) | |
#find out when someone followed you | |
followers.sample.timestamp | |
#find your 'bros' (people who you follow and follow you back) | |
u.bros | |
#see all your new followers this month | |
a = u.followers(at: Time.now.beginning_of_month) | |
b = u.followers(at: Time.now) | |
new = b-a | |
ap u => (SEE BELOW FOR OUTPUT) |
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
This is the output of my structure from the ap gem. How should I persist this? redis, postgres, etc??? | |
It's basically two hashes one for followers and friends. The keys are dates and each key has an array events. | |
#<User:0x7fe08dd169b8 | |
attr_accessor :followers = #<Timeline:0x7fe08dd16940 | |
attr_reader :hash = { | |
"2012.07.23" => [ | |
[0] { | |
:event => :follow, | |
:follower => 4, | |
:followee => 1 | |
} | |
] | |
}, | |
attr_reader :length = 1 | |
>, | |
attr_accessor :friends = #<Timeline:0x7fe08dd16990 | |
attr_reader :hash = { | |
"2012.07.19" => [ | |
[0] { | |
:event => :follow, | |
:follower => 1, | |
:followee => 2 | |
} | |
], | |
"2012.07.22" => [ | |
[0] { | |
:event => :follow, | |
:follower => 1, | |
:followee => 3 | |
} | |
], | |
"2012.07.23" => [ | |
[0] { | |
:event => :follow, | |
:follower => 1, | |
:followee => 23 | |
}, | |
[1] { | |
:event => :follow, | |
:follower => 1, | |
:followee => 33 | |
} | |
], | |
"2012.07.24" => [ | |
[0] { | |
:event => :unfollow, | |
:follower => 1, | |
:followee => 2 | |
} | |
] | |
}, | |
attr_reader :length = 5 | |
>, | |
attr_accessor :id = 1 | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment