Class: Datasets::HouseOfCouncillor
- Defined in:
- lib/datasets/house-of-councillor.rb
Defined Under Namespace
Classes: Bill, InHouseGroup, Member, Question
Constant Summary collapse
- VALID_TYPES =
[ :bill, :in_house_group, :member, :question ]
Instance Attribute Summary
Attributes inherited from Dataset
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type: :bill) ⇒ HouseOfCouncillor
constructor
A new instance of HouseOfCouncillor.
Methods inherited from Dataset
Constructor Details
#initialize(type: :bill) ⇒ HouseOfCouncillor
Returns a new instance of HouseOfCouncillor.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/datasets/house-of-councillor.rb', line 103 def initialize(type: :bill) super() @type = type unless VALID_TYPES.include?(type) = +":type must be one of [" << VALID_TYPES.collect(&:inspect).join(", ") << "]: #{@type.inspect}" raise ArgumentError, end .id = "house-of-councillor" .name = "Bill, in-House group, member and question of the House of Councillors of Japan" .url = "https://smartnews-smri.github.io/house-of-councillors" .licenses = ["MIT"] .description = "The House of Councillors of Japan (type: #{@type})" end |
Instance Method Details
#each ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/datasets/house-of-councillor.rb', line 120 def each return to_enum(__method__) unless block_given? open_data do |csv| csv.each do |row| case @type when :bill record = Bill.new(*row.fields) when :in_house_group record = InHouseGroup.new(*row.fields) when :member %w(当選年).each do |ints_column_name| row[ints_column_name] = parse_ints(row[ints_column_name]) end record = Member.new(*row.fields) when :question record = Question.new(*row.fields) end yield(record) end end end |