virility 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,8 +18,10 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- stats = Virility::Excitation.new(the_url_you_want_to_collect_data_for)
22
- stats.get_virility
21
+ stats = Virility::Excitation.new("http://rubygems.org")
22
+ stats.poll # returns a hash with the collected output of all data sources
23
+ stats.counts # returns a hash of just the virility counts => {:delicious=>943, :facebook=>72, :pinterest=>0, :plusone=>137, :stumbleupon=>1488, :twitter=>2319}
24
+ stats.total # returns the sum of all virility counts
23
25
 
24
26
  Currently there is support for the following social resources:
25
27
  * Facebook
@@ -19,15 +19,18 @@ module Virility
19
19
  #
20
20
 
21
21
  def get_virility
22
- @strategies.each do |name, strategy|
23
- begin
24
- @results[symbolize_for_key(strategy)] = strategy.get_virility
25
- rescue => e
26
- puts "[virility] #{strategy.class.to_s} => #{e}"
22
+ if @results.empty?
23
+ @strategies.each do |name, strategy|
24
+ begin
25
+ @results[symbolize_for_key(strategy)] = strategy.get_virility
26
+ rescue => e
27
+ puts "[virility] #{strategy.class.to_s} => #{e}"
28
+ end
27
29
  end
28
30
  end
29
31
  @results
30
32
  end
33
+ alias :poll :get_virility
31
34
 
32
35
  def get_response(strategy)
33
36
  @strategies[strategy].response if @strategies[strategy]
@@ -38,15 +41,23 @@ module Virility
38
41
  #
39
42
 
40
43
  def counts
41
- @strategies.each do |name, strategy|
42
- begin
43
- @counts[symbolize_for_key(strategy)] = strategy.count.to_i
44
- rescue => e
45
- puts "[virility] #{strategy.class.to_s} => #{e}"
44
+ get_virility
45
+ if @counts.empty?
46
+ @strategies.each do |name, strategy|
47
+ begin
48
+ @counts[symbolize_for_key(strategy)] = strategy.count.to_i
49
+ rescue => e
50
+ puts "[virility] #{strategy.class.to_s} => #{e}"
51
+ end
46
52
  end
47
53
  end
48
54
  @counts
49
55
  end
56
+
57
+ def total_virility
58
+ counts.values.inject(0) { |result, count| result + count }
59
+ end
60
+ alias :total :total_virility
50
61
 
51
62
  #
52
63
  # Gather all of the Strategies
@@ -101,7 +112,7 @@ module Virility
101
112
  #
102
113
 
103
114
  def attributes
104
- {:url => @url}
115
+ {:url => @url, :available_strategies => @strategies.keys}
105
116
  end
106
117
 
107
118
  end
@@ -1,3 +1,3 @@
1
1
  module Virility
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -87,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  segments:
89
89
  - 0
90
- hash: 1510304708477334042
90
+ hash: 1817912261996306322
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  none: false
93
93
  requirements:
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  segments:
98
98
  - 0
99
- hash: 1510304708477334042
99
+ hash: 1817912261996306322
100
100
  requirements: []
101
101
  rubyforge_project:
102
102
  rubygems_version: 1.8.24