Class: Poll
- Inherits:
-
Object
- Object
- Poll
- Defined in:
- lib/lita/handlers/poll.rb
Constant Summary collapse
- ID_LEN =
3- ID_REGEXP =
"(\\w{#{ID_LEN}})"
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(topic, id = nil, options = nil, votes = nil) ⇒ Poll
constructor
A new instance of Poll.
- #options ⇒ Object
- #set_option(opt) ⇒ Object
- #to_json(*args) ⇒ Object
- #topic ⇒ Object
- #valid_vote?(optNum) ⇒ Boolean
- #vote(user, optNum) ⇒ Object
- #votes ⇒ Object
Constructor Details
#initialize(topic, id = nil, options = nil, votes = nil) ⇒ Poll
Returns a new instance of Poll.
7 8 9 10 11 12 |
# File 'lib/lita/handlers/poll.rb', line 7 def initialize(topic, id=nil, =nil, votes=nil) @topic = topic @id = id.nil? ? Digest::SHA1.hexdigest(topic).slice(0, ID_LEN) : id = .nil? ? [] : @votes = votes.nil? ? {} : votes end |
Class Method Details
.json_create(o) ⇒ Object
48 49 50 |
# File 'lib/lita/handlers/poll.rb', line 48 def self.json_create(o) new(o["topic"], o["id"], o["options"], o["votes"]) end |
Instance Method Details
#id ⇒ Object
18 19 20 |
# File 'lib/lita/handlers/poll.rb', line 18 def id return @id end |
#options ⇒ Object
22 23 24 |
# File 'lib/lita/handlers/poll.rb', line 22 def return end |
#set_option(opt) ⇒ Object
30 31 32 |
# File 'lib/lita/handlers/poll.rb', line 30 def set_option(opt) .push(opt) end |
#to_json(*args) ⇒ Object
42 43 44 45 46 |
# File 'lib/lita/handlers/poll.rb', line 42 def to_json(*args) { "id" => @id, "topic" => @topic, "options" => , "votes" => @votes }.to_json(*args) end |
#topic ⇒ Object
14 15 16 |
# File 'lib/lita/handlers/poll.rb', line 14 def topic return @topic end |
#valid_vote?(optNum) ⇒ Boolean
34 35 36 |
# File 'lib/lita/handlers/poll.rb', line 34 def valid_vote?(optNum) optNum-1 < .length end |
#vote(user, optNum) ⇒ Object
38 39 40 |
# File 'lib/lita/handlers/poll.rb', line 38 def vote(user, optNum) @votes[user.id] = optNum end |
#votes ⇒ Object
26 27 28 |
# File 'lib/lita/handlers/poll.rb', line 26 def votes return @votes end |