Class: ADNCV::Data
- Inherits:
-
Object
- Object
- ADNCV::Data
- Defined in:
- lib/ADNCV/data.rb
Instance Attribute Summary collapse
-
#all_clients ⇒ Object
readonly
Returns the value of attribute all_clients.
-
#all_links ⇒ Object
readonly
Returns the value of attribute all_links.
-
#all_mentioned ⇒ Object
readonly
Returns the value of attribute all_mentioned.
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#directed_users ⇒ Object
readonly
Returns the value of attribute directed_users.
-
#export_path ⇒ Object
Returns the value of attribute export_path.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#leadings ⇒ Object
readonly
Returns the value of attribute leadings.
-
#mentions ⇒ Object
readonly
Returns the value of attribute mentions.
-
#mentions_not_directed ⇒ Object
readonly
Returns the value of attribute mentions_not_directed.
-
#mentions_not_replies ⇒ Object
readonly
Returns the value of attribute mentions_not_replies.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#replies ⇒ Object
readonly
Returns the value of attribute replies.
-
#reposts ⇒ Object
readonly
Returns the value of attribute reposts.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#stars ⇒ Object
readonly
Returns the value of attribute stars.
-
#with_links ⇒ Object
readonly
Returns the value of attribute with_links.
-
#without_mentions ⇒ Object
readonly
Returns the value of attribute without_mentions.
Instance Method Summary collapse
- #export ⇒ Object
- #extract(file) ⇒ Object
-
#initialize ⇒ Data
constructor
A new instance of Data.
Constructor Details
#initialize ⇒ Data
Returns a new instance of Data.
8 9 10 |
# File 'lib/ADNCV/data.rb', line 8 def initialize end |
Instance Attribute Details
#all_clients ⇒ Object (readonly)
Returns the value of attribute all_clients.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def all_clients @all_clients end |
#all_links ⇒ Object (readonly)
Returns the value of attribute all_links.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def all_links @all_links end |
#all_mentioned ⇒ Object (readonly)
Returns the value of attribute all_mentioned.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def all_mentioned @all_mentioned end |
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def clients @clients end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def count @count end |
#directed_users ⇒ Object (readonly)
Returns the value of attribute directed_users.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def directed_users @directed_users end |
#export_path ⇒ Object
Returns the value of attribute export_path.
6 7 8 |
# File 'lib/ADNCV/data.rb', line 6 def export_path @export_path end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def filename @filename end |
#leadings ⇒ Object (readonly)
Returns the value of attribute leadings.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def leadings @leadings end |
#mentions ⇒ Object (readonly)
Returns the value of attribute mentions.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def mentions @mentions end |
#mentions_not_directed ⇒ Object (readonly)
Returns the value of attribute mentions_not_directed.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def mentions_not_directed @mentions_not_directed end |
#mentions_not_replies ⇒ Object (readonly)
Returns the value of attribute mentions_not_replies.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def mentions_not_replies @mentions_not_replies end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def names @names end |
#replies ⇒ Object (readonly)
Returns the value of attribute replies.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def replies @replies end |
#reposts ⇒ Object (readonly)
Returns the value of attribute reposts.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def reposts @reposts end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def sources @sources end |
#stars ⇒ Object (readonly)
Returns the value of attribute stars.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def stars @stars end |
#with_links ⇒ Object (readonly)
Returns the value of attribute with_links.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def with_links @with_links end |
#without_mentions ⇒ Object (readonly)
Returns the value of attribute without_mentions.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def without_mentions @without_mentions end |
Instance Method Details
#export ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ADNCV/data.rb', line 76 def export export = { meta: { created_at: Time.now, from_file: @filename, with_version: VERSION }, data: { posts: { total: @count, data: [{ without_mentions: @without_mentions, directed: @leadings, directed_to_unique_users: @directed_users.size, with_mentions_not_directed: @mentions_not_directed, with_mentions_are_replies: @replies, with_mentions_are_not_replies: @mentions_not_replies, with_links: @with_links, have_been_reposted: @reposts, have_been_starred: @stars }] }, users: { total: @all_mentioned.size, data: @all_mentioned.reverse }, clients: { total: @all_clients.size, data: @all_clients.reverse }, links: { total: @with_links, data: @all_links } } } @export_path = "#{Dir.home}/adncv_export.json" File.write(@export_path, export.to_json) end |
#extract(file) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ADNCV/data.rb', line 12 def extract(file) @filename = file decoded = JSON.parse(File.read(file)) @count = decoded.size links = [] @mentions = 0 @leadings = 0 @replies = 0 @with_links = 0 @reposts = 0 @stars = 0 mentioned = Hash.new(0) directed = Hash.new(0) is_reply = Hash.new(0) @clients = Hash.new(0) decoded.each do |post| @clients[post["source"]["name"]] += 1 m = post["entities"]["mentions"] l = post["entities"]["links"] unless m.empty? @mentions += 1 first = m[0]["name"] if m[0]["is_leading"] == true @leadings += 1 directed[first] += 1 unless post["reply_to"].nil? @replies += 1 is_reply[first] += 1 end end m.each do |obj| mentioned[obj["name"]] += 1 end end unless l.empty? @with_links += 1 l.each do |link| links << link['url'] end end unless post["num_reposts"].nil? @reposts += post["num_reposts"] end unless post["num_stars"].nil? @stars += post["num_stars"] end end all_directed = directed.sort_by {|k,v| v} @all_clients = @clients.sort_by {|k,v| v} @all_mentioned = mentioned.sort_by {|k,v| v}.uniq @all_links = links.uniq.sort @names = @all_mentioned.map {|k,v| "@#{k} (#{v})"} @sources = @all_clients.map {|k,v| "#{k} (#{v})"} @directed_users = all_directed.uniq.map {|k,v| "@#{k} (#{v})"} @without_mentions = count - @mentions @mentions_not_directed = @mentions - @leadings @mentions_not_replies = @mentions - @replies end |