Skip to content

Commit

Permalink
Add question type
Browse files Browse the repository at this point in the history
  • Loading branch information
tikkss committed Nov 27, 2023
1 parent fc34556 commit bfd262f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
9 changes: 9 additions & 0 deletions example/house-of-councillor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@
record.professional_name_reading,
]
end

# Question
house_of_councillor = Datasets::HouseOfCouncillor.new(type: :question)
house_of_councillor.each do |record|
# Select number of submissions greater than 1
next unless 1 < record.number_of_submissions

p record.number_of_submissions, record.values
end
22 changes: 21 additions & 1 deletion lib/datasets/house-of-councillor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,26 @@ class HouseOfCouncillor < Dataset
:career,
:career_on)

Question = Struct.new(:submit_time,
:submit_number,
:title,
:submitter,
:number_of_submissions,
:question_for_text_html_url,
:answer_for_text_html_url,
:question_for_text_pdf_url,
:answer_for_text_pdf_url,
:question_url,
:submitted_on,
:transfered_on,
:received_answer_on,
:notes)

VALID_TYPES = [
:bill,
:in_house_group,
:member,
:question
]

def initialize(type: :bill)
Expand All @@ -95,7 +111,7 @@ def initialize(type: :bill)
end

@metadata.id = "house-of-councillor"
@metadata.name = "Bill, in-House group, member of the House of Councillors of Japan"
@metadata.name = "Bill, in-House group, member and question of the House of Councillors of Japan"
@metadata.url = "https://smartnews-smri.github.io/house-of-councillors"
@metadata.licenses = ["MIT"]
@metadata.description = "The House of Councillors of Japan (type: #{@type})"
Expand All @@ -113,6 +129,8 @@ def each
record = InHouseGroup.new(*row.fields)
when :member
record = Member.new(*row.fields)
when :question
record = Question.new(*row.fields)
end
yield(record)
end
Expand All @@ -130,6 +148,8 @@ def open_data
data_url << "/kaiha.csv"
when :member
data_url << "/giin.csv"
when :question
data_url << "/syuisyo.csv"
end
data_path = cache_dir_path + "#{@type}.csv"
download(data_path, data_url)
Expand Down
50 changes: 50 additions & 0 deletions test/test-house-of-councillor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,54 @@ def record(*args)
])
end
end

sub_test_case(":question") do
def setup
@dataset = Datasets::HouseOfCouncillor.new(type: :question)
end

def record(*args)
Datasets::HouseOfCouncillor::Question.new(*args)
end

test("#each") do
records = @dataset.each.to_a
assert_equal([
7518,
record(1,
1,
"食生活安定に関する質問主意書",
"市来 乙彦",
1,
"https://www.sangiin.go.jp/japanese/joho1/kousei/syuisyo/001/syuh/s001001.htm",
"https://www.sangiin.go.jp/japanese/joho1/kousei/syuisyo/001/touh/t001001.htm",
"https://www.sangiin.go.jp/japanese/joho1/kousei/syuisyo/001/syup/s001001.pdf",
"https://www.sangiin.go.jp/japanese/joho1/kousei/syuisyo/001/toup/t001001.pdf",
"https://www.sangiin.go.jp/japanese/joho1/kousei/syuisyo/001/meisai/m001001.htm",
Date.parse("1947-06-06"),
Date.parse("1947-06-23"),
Date.parse("1947-06-28"),
nil),
record(212,
67,
"公的機関の職員の国籍に関する再質問主意書",
"神谷 宗幣",
1,
nil,
nil,
nil,
nil,
"https://www.sangiin.go.jp/japanese/joho1/kousei/syuisyo/212/meisai/m212067.htm",
Date.parse("2023-11-24"),
nil,
nil,
nil),
],
[
records.size,
records.first,
records.last,
])
end
end
end

0 comments on commit bfd262f

Please sign in to comment.