Class: WordCountAPI
- Inherits:
-
Object
- Object
- WordCountAPI
- Defined in:
- lib/wordcount.rb
Constant Summary collapse
- WORDCOUNT_URL =
"http://YEAR.nanowrimo.org/modules/wcapi/wc.php?uid=UID"
- WORDCOUNT_HISTORY_URL =
"http://YEAR.nanowrimo.org/modules/wcapi/wchistory.php?uid=UID"
Instance Attribute Summary collapse
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
- #count ⇒ Object
- #history ⇒ Object
-
#initialize(uid, year = Time.new.year) ⇒ WordCountAPI
constructor
A new instance of WordCountAPI.
- #name ⇒ Object
Constructor Details
#initialize(uid, year = Time.new.year) ⇒ WordCountAPI
Returns a new instance of WordCountAPI.
11 12 13 14 |
# File 'lib/wordcount.rb', line 11 def initialize(uid, year=Time.new.year) @uid = uid @year = year end |
Instance Attribute Details
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
6 7 8 |
# File 'lib/wordcount.rb', line 6 def uid @uid end |
Instance Method Details
#count ⇒ Object
23 24 25 26 27 28 |
# File 'lib/wordcount.rb', line 23 def count url = WORDCOUNT_URL.gsub(/UID/, @uid.to_s) url.gsub! /YEAR/, @year.to_s doc = Hpricot(open(url).read) (doc/'user_wordcount').inner_html.to_i end |
#history ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wordcount.rb', line 30 def history url = WORDCOUNT_HISTORY_URL.gsub(/UID/, @uid.to_s) url.gsub! /YEAR/, @year.to_s history = {} doc = Hpricot(open(url).read) (doc/'wcentry').each do |entry| history[(entry/'wcdate').inner_html] = (entry/'wc').inner_html end history end |
#name ⇒ Object
16 17 18 19 20 21 |
# File 'lib/wordcount.rb', line 16 def name url = WORDCOUNT_URL.gsub(/UID/, @uid.to_s) url.gsub! /YEAR/, @year.to_s doc = Hpricot(open(url).read) (doc/'uname').inner_html end |