Class: PollEverywhere::Models::MultipleChoicePoll
- Defined in:
- lib/polleverywhere/models.rb
Defined Under Namespace
Classes: Option
Instance Attribute Summary
Attributes inherited from Poll
Instance Method Summary collapse
- #fetch ⇒ Object
-
#options ⇒ Object
Choices for a multiple choice poll.
-
#options=(options) ⇒ Object
Accept an array of options as strings, hashes, or options objects.
-
#to_hash ⇒ Object
Add the serialize options hash to the meix.
Methods inherited from Poll
all, #archive, #clear, #destroy, get, #initialize, #path, #persisted?, #possible_states, #results, #save, #start, #stop
Methods included from Serializable
Constructor Details
This class inherits a constructor from PollEverywhere::Models::Poll
Instance Method Details
#fetch ⇒ Object
275 276 277 278 279 |
# File 'lib/polleverywhere/models.rb', line 275 def fetch http.get.from(path).as(:json).response do |response| from_json response.body end end |
#options ⇒ Object
Choices for a multiple choice poll
256 257 258 |
# File 'lib/polleverywhere/models.rb', line 256 def @options ||= [] end |
#options=(options) ⇒ Object
Accept an array of options as strings, hashes, or options objects.
261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/polleverywhere/models.rb', line 261 def () @options = .map do |val| case val when Option val.poll = self val when Hash Option.new(self).from_hash(val) else Option.new(self).from_hash(:value => val.to_s) end end end |
#to_hash ⇒ Object
Add the serialize options hash to the meix
282 283 284 285 286 |
# File 'lib/polleverywhere/models.rb', line 282 def to_hash hash = super hash[:multiple_choice_poll][:options] = .map(&:to_hash) hash end |