wordcount 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wordcount'
4
+
5
+ wc = NaNoWriMo::WordCountAPI.new(119458,2005)
6
+ puts "Total Count for 2005: " +wc.count.to_s + " words"
7
+ puts "History Follows: "
8
+ wc.history.each do |k,v|
9
+ puts k+": "+v
10
+ end
11
+
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require_gem 'wordcount'
3
+ require 'camping'
4
+ require 'gruff'
5
+ require 'date'
6
+ Camping.goes :NaNoWriMo
7
+ module NaNoWriMo::Controllers
8
+ class Index < R '/'
9
+ def get
10
+ wc = WordCountAPI.new 119458,2006
11
+ data = []
12
+ labels = {}
13
+ wc.history.values.each do |value|
14
+ data << value.to_i
15
+ end
16
+ count=0
17
+ wc.history.keys.each do |key|
18
+ labels[count] = Date.parse(key).day.to_s
19
+ count += 1
20
+ end
21
+ uname = wc.name
22
+ g = Gruff::Line.new(400)
23
+ g.title = "NaNoWriMo 2005 for "+uname
24
+ g.data "Count", data,"red"
25
+ g.labels= labels
26
+ g.theme_37signals
27
+ g.x_axis_label = "Day"
28
+ g.y_axis_label = "Words"
29
+ g.write('nanowrimo/static/word_count.png')
30
+ render :index
31
+ end
32
+ end
33
+ end
34
+
35
+ module NaNoWriMo::Views
36
+ def layout
37
+ xhtml_strict do
38
+ head do
39
+ title "NaNoWriMo Progress"
40
+ end
41
+ body do
42
+ self << yield
43
+ end
44
+ end
45
+ end
46
+ def index
47
+ img :src => '/static/word_count.png'
48
+ div do
49
+ p "The above graph represents my current progress in the 2006 NaNoWriMo competition."
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = "wordcount"
5
+ s.version = "1.0.0"
6
+ s.author = "Michael Gorsuch"
7
+ s.email = "michael.gorsuch@gmail.com"
8
+ s.homepage = "http://code.styledbits.com/wordcount"
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = "wordcount is a simple Ruby interface to the NaNoWriMo Word Count API"
11
+ candidates = Dir.glob("{bin,docs,lib,test,examples}/**/*")
12
+ s.files = candidates.delete_if do |item|
13
+ item.include?(".svn") || item.include?("rdoc")
14
+ end
15
+ s.require_path = 'lib'
16
+ s.autorequire = 'wordcount'
17
+ s.add_dependency("hpricot")
18
+ end
19
+
20
+ if $0 == __FILE__
21
+ Gem::manage_gems
22
+ Gem::Builder.new(spec).build
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'open-uri'
3
+ require 'hpricot'
4
+
5
+ class WordCountAPI
6
+ attr_reader :uid
7
+
8
+ WORDCOUNT_URL = "http://YEAR.nanowrimo.org/modules/wcapi/wc.php?uid=UID"
9
+ WORDCOUNT_HISTORY_URL = "http://YEAR.nanowrimo.org/modules/wcapi/wchistory.php?uid=UID"
10
+
11
+ def initialize(uid, year=Time.new.year)
12
+ @uid = uid
13
+ @year = year
14
+ end
15
+
16
+ def name
17
+ url = WORDCOUNT_URL.gsub(/UID/, @uid.to_s)
18
+ url.gsub! /YEAR/, @year.to_s
19
+ doc = Hpricot(open(url).read)
20
+ (doc/'uname').inner_html
21
+ end
22
+
23
+ def count
24
+ url = WORDCOUNT_URL.gsub(/UID/, @uid.to_s)
25
+ url.gsub! /YEAR/, @year.to_s
26
+ doc = Hpricot(open(url).read)
27
+ (doc/'user_wordcount').inner_html.to_i
28
+ end
29
+
30
+ def history
31
+ url = WORDCOUNT_HISTORY_URL.gsub(/UID/, @uid.to_s)
32
+ url.gsub! /YEAR/, @year.to_s
33
+
34
+ history = {}
35
+
36
+ doc = Hpricot(open(url).read)
37
+ (doc/'wcentry').each do |entry|
38
+ history[(entry/'wcdate').inner_html] = (entry/'wc').inner_html
39
+ end
40
+ history
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: wordcount
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2006-10-29 00:00:00 -04:00
8
+ summary: wordcount is a simple Ruby interface to the NaNoWriMo Word Count API
9
+ require_paths:
10
+ - lib
11
+ email: michael.gorsuch@gmail.com
12
+ homepage: http://code.styledbits.com/wordcount
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: wordcount
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Michael Gorsuch
30
+ files:
31
+ - lib/build.rb
32
+ - lib/wordcount.rb
33
+ - examples/example.rb
34
+ - examples/ghoststory.rb
35
+ test_files: []
36
+
37
+ rdoc_options: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ requirements: []
46
+
47
+ dependencies:
48
+ - !ruby/object:Gem::Dependency
49
+ name: hpricot
50
+ version_requirement:
51
+ version_requirements: !ruby/object:Gem::Version::Requirement
52
+ requirements:
53
+ - - ">"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.0.0
56
+ version: