Sha256: 9e5929c28fe969a7330e791e89b413ba8c915d87b1594a574481b3e2ace2f4e3
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
module Pollster class Poll < Base attr_reader :start_date, :end_date, :method, :pollster, :url, :source, :questions def initialize(params={}) params.each_pair do |k,v| instance_variable_set("@#{k}", v) end end # Get a list of all polls. # Polls are listed in pages of 25. def self.all(params={}) page = params[:page] || 1 invoke('polls', {:page => page}).map { |poll| self.create(poll) } end # Get a list of polls based on the given parameters. # See API documentation for acceptable parameters. def self.where(params={}) if params.empty? raise "A search parameter is required" end invoke('polls', params).map { |poll| self.create(poll) } end private def self.create(data) data = hash_keys_to_sym(data) data[:questions] = data[:questions].map { |question| hash_keys_to_sym(question) } data[:questions].each { |question| question[:responses] = question[:responses].map { |response| hash_keys_to_sym(response) } } data[:start_date] = Date.parse(data[:start_date]) data[:end_date] = Date.parse(data[:end_date]) self.new(data) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pollster-0.1.1 | lib/pollster/poll.rb |
pollster-0.1.0 | lib/pollster/poll.rb |