Class: Pollster::Chart
Constant Summary
Constants inherited from Base
Base::API_BASE, Base::API_SERVER
Instance Attribute Summary collapse
-
#estimates ⇒ Object
readonly
Returns the value of attribute estimates.
-
#estimates_by_date ⇒ Object
readonly
Returns the value of attribute estimates_by_date.
-
#last_updated ⇒ Object
readonly
Returns the value of attribute last_updated.
-
#poll_count ⇒ Object
readonly
Returns the value of attribute poll_count.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.all ⇒ Object
Get a list of all charts.
-
.find(slug) ⇒ Object
Get a chart based on its slug.
-
.where(params = {}) ⇒ Object
Get a list of charts based on the given parameters.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Chart
constructor
A new instance of Chart.
- #inspect ⇒ Object
-
#polls(params = {}) ⇒ Object
Get a list of polls for this chart.
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Chart
Returns a new instance of Chart.
7 8 9 10 11 |
# File 'lib/pollster/chart.rb', line 7 def initialize(params={}) params.each_pair do |k,v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#estimates ⇒ Object (readonly)
Returns the value of attribute estimates.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def estimates @estimates end |
#estimates_by_date ⇒ Object (readonly)
Returns the value of attribute estimates_by_date.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def estimates_by_date @estimates_by_date end |
#last_updated ⇒ Object (readonly)
Returns the value of attribute last_updated.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def last_updated @last_updated end |
#poll_count ⇒ Object (readonly)
Returns the value of attribute poll_count.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def poll_count @poll_count end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def slug @slug end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def state @state end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def title @title end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def topic @topic end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/pollster/chart.rb', line 5 def url @url end |
Class Method Details
.all ⇒ Object
Get a list of all charts.
19 20 21 |
# File 'lib/pollster/chart.rb', line 19 def self.all invoke('charts').map { |chart| self.create(chart) } end |
.find(slug) ⇒ Object
Get a chart based on its slug.
24 25 26 |
# File 'lib/pollster/chart.rb', line 24 def self.find(slug) self.create invoke("charts/#{slug}") end |
.where(params = {}) ⇒ Object
Get a list of charts based on the given parameters. See API documentation for acceptable parameters.
30 31 32 33 34 35 |
# File 'lib/pollster/chart.rb', line 30 def self.where(params={}) if params.empty? raise "A search parameter is required" end invoke('charts', params).map { |chart| self.create(chart) } end |
Instance Method Details
#inspect ⇒ Object
41 42 43 |
# File 'lib/pollster/chart.rb', line 41 def inspect "<#{self.class}: #{self.title}>" end |
#polls(params = {}) ⇒ Object
Get a list of polls for this chart.
14 15 16 |
# File 'lib/pollster/chart.rb', line 14 def polls(params={}) Poll.where(params.merge({:chart => self.slug})) end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/pollster/chart.rb', line 37 def to_s "#{self.class}: #{self.title}" end |