Class: Datasets::HouseOfCouncillor

Inherits:
Dataset
  • Object
show all
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

#metadata

Instance Method Summary collapse

Methods inherited from Dataset

#clear_cache!, #to_table

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)
    message = +":type must be one of ["
    message << VALID_TYPES.collect(&:inspect).join(", ")
    message << "]: #{@type.inspect}"
    raise ArgumentError, message
  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

#eachObject



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