Class: Pollster::QuestionPollResponsesRaw
- Inherits:
-
Object
- Object
- Pollster::QuestionPollResponsesRaw
- Includes:
- Enumerable
- Defined in:
- lib/pollster/models/question_poll_responses_raw.rb
Constant Summary collapse
- HeaderLineRegex =
/\Aresponse_text\tpollster_label\tvalue\tpoll_slug\tsurvey_house\tstart_date\tend_date\tquestion_text\tsample_subpopulation\tobservations\tmargin_of_error\tmode\tpartisanship\tpartisan_affiliation\b/
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(array) ⇒ QuestionPollResponsesRaw
constructor
A new instance of QuestionPollResponsesRaw.
Constructor Details
#initialize(array) ⇒ QuestionPollResponsesRaw
Returns a new instance of QuestionPollResponsesRaw.
68 69 70 |
# File 'lib/pollster/models/question_poll_responses_raw.rb', line 68 def initialize(array) @array = array end |
Class Method Details
.from_tsv(tsv) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/pollster/models/question_poll_responses_raw.rb', line 76 def self.from_tsv(tsv) lines = tsv.split(/(?:\r?\n)+/).reject(&:empty?) if m = HeaderLineRegex.match(lines[0]) rows = lines[1..-1].map { |tsv_line| QuestionPollResponseRaw.from_tsv_line(tsv_line) } QuestionPollResponsesRaw.new(rows) else raise ArgumentError.new("First line of TSV is `#{lines[0]}`, which does not match Pollster::QuestionPollResponsesRaw::HeaderLineRegex") end end |
Instance Method Details
#each(&block) ⇒ Object
72 73 74 |
# File 'lib/pollster/models/question_poll_responses_raw.rb', line 72 def each(&block) @array.each(&block) end |