Class: VoteSmart::Rating

Inherits:
Common
  • Object
show all
Defined in:
lib/vote_smart/rating.rb

Class Method Summary collapse

Methods inherited from Common

construct_url, get_json_data, hash2get, #initialize, parallelize!, request, response_child, session, set_attribute_map, #update_attributes

Constructor Details

This class inherits a constructor from VoteSmart::Common

Class Method Details

.get_candidate_rating(candidate_id, sig_id, &block) ⇒ Object

Returns an SIG’s rating on a specific candidate



38
39
40
# File 'lib/vote_smart/rating.rb', line 38

def self.get_candidate_rating candidate_id, sig_id, &block
  request("Rating.getCandidateRating", {"candidateId" => candidate_id, "sigId" => sig_id}, &block)
end

.get_categories(state_id = nil) ⇒ Object

Returns categories with ratings according to state_id(NA = fed)



6
7
8
# File 'lib/vote_smart/rating.rb', line 6

def self.get_categories state_id = nil
  request("Rating.getCategories", "stateId" => state_id)
end

.get_sig(sig_id) ⇒ Object

Returns detailed SIG information



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vote_smart/rating.rb', line 16

def self.get_sig sig_id
  result = request("Rating.getSig", "sigId" => sig_id)
  # PVS return utf control codes for punction in descriptions
  if result['sig']['description'].first == '"'
    result['sig']['description'] = result['sig']['description'][1..-2]
  end
  result['sig']['description'] = result['sig']['description'].unpack("U*").map do |char|
    case char
    when 146 # 0092
      39
    when 148, 147 # 0093,4
      34
    when 150, 151 # 0096,7
      45
    else
      char
    end
  end.pack("U*")
  result
end

.get_sig_list(category_id, state_id = 'NA') ⇒ Object

Returns a list of SIGs with ratings in category and state



11
12
13
# File 'lib/vote_smart/rating.rb', line 11

def self.get_sig_list category_id, state_id = 'NA'
  request("Rating.getSigList", "categoryId" => category_id, "stateId" => state_id)
end