Class: PollEverywhere::Models::MultipleChoicePoll

Inherits:
Poll
  • Object
show all
Defined in:
lib/polleverywhere/models.rb

Defined Under Namespace

Classes: Option

Instance Attribute Summary

Attributes inherited from Poll

#http

Instance Method Summary collapse

Methods inherited from Poll

all, #destroy, get, #initialize, #path, #persisted?, #possible_states, #save, #start, #stop

Methods included from Serializable

included

Constructor Details

This class inherits a constructor from PollEverywhere::Models::Poll

Instance Method Details

#fetchObject



215
216
217
218
219
# File 'lib/polleverywhere/models.rb', line 215

def fetch
  http.get.from(path).as(:json).response do |response|
    from_json response.body
  end
end

#optionsObject

Choices for a multiple choice poll



196
197
198
# File 'lib/polleverywhere/models.rb', line 196

def options
  @options ||= []
end

#options=(options) ⇒ Object

Accept an array of options as strings, hashes, or options objects.



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/polleverywhere/models.rb', line 201

def options=(options)
  @options = 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_hashObject

Add the serialize options hash to the meix



222
223
224
225
226
# File 'lib/polleverywhere/models.rb', line 222

def to_hash
  hash = super
  hash[:multiple_choice_poll][:options] = options.map(&:to_hash)
  hash
end