Class: Biostars::API::Stats
- Inherits:
-
Object
- Object
- Biostars::API::Stats
- Defined in:
- lib/biostars/api/stats.rb
Instance Attribute Summary collapse
-
#answers ⇒ Fixnum
readonly
Total number of answers as of the given day/date.
-
#comments ⇒ Fixnum
readonly
Total number of comments as of the given day/date .
-
#date ⇒ String
readonly
The current date, ISO 8601 format.
-
#new_posts ⇒ Array
readonly
Number of new posts in the given day/date .
-
#new_users ⇒ Array
readonly
Number of new users in the given day/date .
-
#new_votes ⇒ Array
readonly
Number of new votes in the given day/date .
-
#questions ⇒ Fixnum
readonly
Total number of questions as of the given day/date.
-
#timestamp ⇒ Fixnum
readonly
Date, unix epoch time format.
-
#toplevel ⇒ Fixnum
readonly
Total number of toplevel post as of the given day/date.
-
#users ⇒ Fixnum
readonly
Total number of users as of the given day/date.
-
#votes ⇒ Fixnum
readonly
Total number of votes as of the given day/date.
Class Method Summary collapse
-
.find_by_date(date = Date.today-1) ⇒ Stats
Statistics as of the given date.
-
.find_by_day(day = Date.today.day) ⇒ Stats
Statistics as of the Nth day after day-0 (the day of the first ever post).
-
.latest ⇒ Stats
Helper method to look up stats for the prior date.
Instance Method Summary collapse
-
#all_posts ⇒ Array
Returns an Array of Post objects for all Posts on the given day/date.
-
#all_users ⇒ Array
Returns an Array of User objects for all Users on the given day/date.
-
#all_votes ⇒ Array
Returns an Array of Vote objects for all Votes on the given day/date.
-
#initialize(attributes) ⇒ Stats
constructor
A new instance of Stats.
Constructor Details
#initialize(attributes) ⇒ Stats
Returns a new instance of Stats.
38 39 40 41 42 |
# File 'lib/biostars/api/stats.rb', line 38 def initialize(attributes) attributes.each do |k,v| instance_variable_set "@#{k}", v unless v.nil? end end |
Instance Attribute Details
#answers ⇒ Fixnum (readonly)
Returns total number of answers as of the given day/date.
6 7 8 |
# File 'lib/biostars/api/stats.rb', line 6 def answers @answers end |
#comments ⇒ Fixnum (readonly)
Returns total number of comments as of the given day/date .
9 10 11 |
# File 'lib/biostars/api/stats.rb', line 9 def comments @comments end |
#date ⇒ String (readonly)
Returns the current date, ISO 8601 format.
12 13 14 |
# File 'lib/biostars/api/stats.rb', line 12 def date @date end |
#new_posts ⇒ Array (readonly)
Returns number of new posts in the given day/date .
15 16 17 |
# File 'lib/biostars/api/stats.rb', line 15 def new_posts @new_posts end |
#new_users ⇒ Array (readonly)
Returns number of new users in the given day/date .
18 19 20 |
# File 'lib/biostars/api/stats.rb', line 18 def new_users @new_users end |
#new_votes ⇒ Array (readonly)
Returns number of new votes in the given day/date .
21 22 23 |
# File 'lib/biostars/api/stats.rb', line 21 def new_votes @new_votes end |
#questions ⇒ Fixnum (readonly)
Returns total number of questions as of the given day/date.
24 25 26 |
# File 'lib/biostars/api/stats.rb', line 24 def questions @questions end |
#timestamp ⇒ Fixnum (readonly)
Returns date, unix epoch time format.
27 28 29 |
# File 'lib/biostars/api/stats.rb', line 27 def @timestamp end |
#toplevel ⇒ Fixnum (readonly)
Returns total number of toplevel post as of the given day/date.
30 31 32 |
# File 'lib/biostars/api/stats.rb', line 30 def toplevel @toplevel end |
#users ⇒ Fixnum (readonly)
Returns total number of users as of the given day/date.
33 34 35 |
# File 'lib/biostars/api/stats.rb', line 33 def users @users end |
#votes ⇒ Fixnum (readonly)
Returns total number of votes as of the given day/date.
36 37 38 |
# File 'lib/biostars/api/stats.rb', line 36 def votes @votes end |
Class Method Details
.find_by_date(date = Date.today-1) ⇒ Stats
Statistics as of the given date.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/biostars/api/stats.rb', line 96 def find_by_date(date=Date.today-1) raise Biostars::StatsError unless date.is_a? Date url = "stats/date/%s/%s/%s" % [ date.year, sprintf('%02d', date.month), sprintf('%02d', date.day), ] find url end |
.find_by_day(day = Date.today.day) ⇒ Stats
Statistics as of the Nth day after day-0 (the day of the first ever post).
85 86 87 88 89 |
# File 'lib/biostars/api/stats.rb', line 85 def find_by_day(day=Date.today.day) raise Biostars::StatsError, "Expecting a Date Object" unless day.is_a? Fixnum find "stats/day/#{day}" end |
.latest ⇒ Stats
Helper method to look up stats for the prior date.
76 77 78 |
# File 'lib/biostars/api/stats.rb', line 76 def latest find_by_date end |
Instance Method Details
#all_posts ⇒ Array
Returns an Array of Post objects for all Posts on the given day/date.
47 48 49 50 51 |
# File 'lib/biostars/api/stats.rb', line 47 def all_posts new_posts.collect do |post_id| Biostars::API::Post.find post_id end end |