Class: BBBEvents::Poll

Inherits:
Object
  • Object
show all
Defined in:
lib/bbbevents/poll.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(poll_event) ⇒ Poll

Returns a new instance of Poll.



5
6
7
8
9
10
11
12
# File 'lib/bbbevents/poll.rb', line 5

def initialize(poll_event)
  @id        = poll_event["pollId"]
  @type      = poll_event["type"]
  @question  = poll_event["question"].nil? ? "" : "#{poll_event['question']}"
  @published = false
  @options   = JSON.parse(poll_event["answers"]).map { |opt| opt["key"] }
  @votes     = {}
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/bbbevents/poll.rb', line 3

def id
  @id
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/bbbevents/poll.rb', line 3

def options
  @options
end

#publishedObject

Returns the value of attribute published.



3
4
5
# File 'lib/bbbevents/poll.rb', line 3

def published
  @published
end

#questionObject

Returns the value of attribute question.



3
4
5
# File 'lib/bbbevents/poll.rb', line 3

def question
  @question
end

#startObject

Returns the value of attribute start.



3
4
5
# File 'lib/bbbevents/poll.rb', line 3

def start
  @start
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/bbbevents/poll.rb', line 3

def type
  @type
end

#votesObject

Returns the value of attribute votes.



3
4
5
# File 'lib/bbbevents/poll.rb', line 3

def votes
  @votes
end

Instance Method Details

#published?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/bbbevents/poll.rb', line 14

def published?
  @published
end

#to_hObject Also known as: as_json



18
19
20
21
22
# File 'lib/bbbevents/poll.rb', line 18

def to_h
  hash = {}
  instance_variables.each { |var| hash[var[1..-1]] = instance_variable_get(var) }
  hash
end

#to_jsonObject



25
26
27
# File 'lib/bbbevents/poll.rb', line 25

def to_json
  JSON.generate(as_json)
end