Skip to content

Commit

Permalink
changed value to option
Browse files Browse the repository at this point in the history
removed list command
  • Loading branch information
TomK32 committed May 28, 2009
1 parent 6d337a2 commit 8b9cb84
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -6,7 +6,7 @@ Various parsers, maily to be used with Twitter
TwitterVote
=======

Let's users create votings or small surveys and vote in those.
Lets users create votings or small surveys and vote in those.


Copyright (c) 2009 Thomas R. Koll <info@ananasblau.com>, released under the MIT license
14 changes: 6 additions & 8 deletions lib/parsers/twitter/vote.rb
Expand Up @@ -6,15 +6,13 @@ class Vote
def parse(input)
case input.split(" ")[1] || input
when /^\@/ # vote by user name
value = input.split(" ")[2..-1].join(' ')
return :error if value.blank?
return :vote, {:user_screen_name => input.split(" ")[1][1..-1], :value => value }
option = input.split(" ")[2..-1].join(' ')
return :error if option.blank?
return :vote, {:user_screen_name => input.split(" ")[1][1..-1], :option => option }
when /^\#?\d+/ # vote by survey id
value = input.split(" ")[2..-1].join(' ')
return :error if value.blank?
return :vote, {:id => input.split(" ")[1][/\d+/], :value => value}
when 'list'
return :list
option = input.split(" ")[2..-1].join(' ')
return :error if option.blank?
return :vote, {:id => input.split(" ")[1][/\d+/], :option => option}
when 'create' # a new survey
else
if input.match(/\?/)
Expand Down
15 changes: 7 additions & 8 deletions test/parsers/twitter/vote_test.rb
Expand Up @@ -11,18 +11,17 @@ def test_02_create_voting_with_options
assert_equal [:create, {:question => 'Is there a god?', :options => %w(Yes Maybe No)}], @parser.parse('Is there a god? Yes. Maybe. No')
assert_equal [:create, {:question => 'Is there a god?', :options => %w(Yes Maybe No)}], @parser.parse('Is there a god? Yes Maybe No')
end
def test_03_list_my_votings
assert_equal :list, @parser.parse('@vote list')
def test_03_vote_on_id
assert_equal [:vote, {:id => '123', :option => 'No'}], @parser.parse('@vote #123 No')
end
def test_04_vote_on_id
assert_equal [:vote, {:id => '123', :value => 'No'}], @parser.parse('@vote #123 No')
def test_04_vote_on_username
assert_equal [:vote, {:user_screen_name => 'TomK32', :option => 'Yes'}], @parser.parse('@vote @TomK32 Yes')
end
def test_05_vote_on_username
assert_equal [:vote, {:user_screen_name => 'TomK32', :value => 'Yes'}], @parser.parse('@vote @TomK32 Yes')
end
def test_06_errors
def test_05_errors
assert_equal :error, @parser.parse('@vote Yes')
assert_equal :error, @parser.parse('@vote @TomK32')
assert_equal :error, @parser.parse('@vote #123')
assert_equal :error, @parser.parse('@vote You look great')
assert_equal :error, @parser.parse('@vote I think @tomk32 looks great')
end
end

0 comments on commit 8b9cb84

Please sign in to comment.