class SocialDataProcessor

Attributes

json_data[R]
stats[R]

Public Instance Methods

data(json_data) click to toggle source
# File lib/contentar/data_processors/social.rb, line 4
def data(json_data)
  @json_data = json_data
  @stats     = get_stats
  process
end

Private Instance Methods

facebook() click to toggle source
# File lib/contentar/data_processors/social.rb, line 36
def facebook
  stats.fetch('facebook') { {} }
end
facebook_comments() click to toggle source
# File lib/contentar/data_processors/social.rb, line 84
def facebook_comments
  facebook.fetch('comment_count') { 0 }
end
facebook_likes() click to toggle source
# File lib/contentar/data_processors/social.rb, line 80
def facebook_likes
  facebook.fetch('like_count') { 0 }
end
facebook_shares() click to toggle source
# File lib/contentar/data_processors/social.rb, line 76
def facebook_shares
  facebook.fetch('share_count') { 0 }
end
get_stats() click to toggle source
# File lib/contentar/data_processors/social.rb, line 23
def get_stats
  dat = JSON.parse(json_data).fetch('data') { return {} }
  dat.fetch('stats') { return dat }
end
google() click to toggle source
# File lib/contentar/data_processors/social.rb, line 32
def google
  stats.fetch('google+') { {} }
end
google_plus_shares() click to toggle source
# File lib/contentar/data_processors/social.rb, line 57
def google_plus_shares
  google.fetch('share_count') { 0 }
end
linkedin_shares() click to toggle source
# File lib/contentar/data_processors/social.rb, line 71
def linkedin_shares
  linkedin = stats.fetch('linkedin') { {} }
  linkedin.fetch('share_count') { 0 }
end
pinterest_shares() click to toggle source
# File lib/contentar/data_processors/social.rb, line 61
def pinterest_shares
  pinterest = stats.fetch('pinterest') { {} }
  pinterest.fetch('share_count') { 0 }
end
process() click to toggle source
# File lib/contentar/data_processors/social.rb, line 12
def process
  {
    stumbleupon_views: stumbleupon_views, reddit_submissions: reddit_submissions,
    reddit_comments: reddit_comments, reddit_score: reddit_score,
    google_plus_shares: google_plus_shares, pinterest_shares: pinterest_shares,
    twitter_shares: twitter_shares, linkedin_shares: linkedin_shares,
    facebook_shares: facebook_shares, facebook_likes: facebook_likes,
    facebook_comments: facebook_comments
  }
end
reddit() click to toggle source
# File lib/contentar/data_processors/social.rb, line 28
def reddit
  stats.fetch('reddit') { {} }
end
reddit_comments() click to toggle source
# File lib/contentar/data_processors/social.rb, line 49
def reddit_comments
  reddit.fetch('comment_total') { 0 }
end
reddit_score() click to toggle source
# File lib/contentar/data_processors/social.rb, line 53
def reddit_score
  reddit.fetch('score_total') { 0 }
end
reddit_submissions() click to toggle source
# File lib/contentar/data_processors/social.rb, line 45
def reddit_submissions
  reddit.fetch('submission_count') { 0 }
end
stumbleupon_views() click to toggle source
# File lib/contentar/data_processors/social.rb, line 40
def stumbleupon_views
  su = stats.fetch('stumbleupon') { return 0 }
  su.fetch('views') { return 0 }
end
twitter_shares() click to toggle source
# File lib/contentar/data_processors/social.rb, line 66
def twitter_shares
  twitter = stats.fetch('twitter') { {} }
  twitter.fetch('share_count') { 0 }
end