Class: Pollster::Chart

Inherits:
Base
  • Object
show all
Defined in:
lib/pollster/chart.rb

Constant Summary

Constants inherited from Base

Base::API_BASE, Base::API_SERVER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#estimatesObject (readonly)

Returns the value of attribute estimates.



5
6
7
# File 'lib/pollster/chart.rb', line 5

def estimates
  @estimates
end

#estimates_by_dateObject (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_updatedObject (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_countObject (readonly)

Returns the value of attribute poll_count.



5
6
7
# File 'lib/pollster/chart.rb', line 5

def poll_count
  @poll_count
end

#slugObject (readonly)

Returns the value of attribute slug.



5
6
7
# File 'lib/pollster/chart.rb', line 5

def slug
  @slug
end

#stateObject (readonly)

Returns the value of attribute state.



5
6
7
# File 'lib/pollster/chart.rb', line 5

def state
  @state
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/pollster/chart.rb', line 5

def title
  @title
end

#topicObject (readonly)

Returns the value of attribute topic.



5
6
7
# File 'lib/pollster/chart.rb', line 5

def topic
  @topic
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/pollster/chart.rb', line 5

def url
  @url
end

Class Method Details

.allObject

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

#inspectObject



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_sObject



37
38
39
# File 'lib/pollster/chart.rb', line 37

def to_s
  "#{self.class}: #{self.title}"
end