class WikidataPositionHistory::Report::Mandate

base report where each row is one person holding an office for a period

Public Instance Methods

template_params() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 13
def template_params
  {
    metadata:   metadata,
    table_rows: table_rows,
    sparql_url: sparql.wdqs_url,
  }
end
wikitext() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 7
def wikitext
  return no_items_output if mandates.empty?

  ReportTemplate.new(template_params).output
end

Private Instance Methods

biodata() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 23
def biodata
  @biodata ||= biodata_sparql.results_as(BioRow)
end
biodata_for(officeholder) click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 27
def biodata_for(officeholder)
  biodata.select { |bio| bio.person.id == officeholder.id }
end
biodata_sparql() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 39
def biodata_sparql
  biodata_query.new(position_id)
end
mandates() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 43
def mandates
  @mandates ||= sparql.results_as(MandateRow)
end
no_items_output() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 47
def no_items_output
  "\n{{PositionHolderHistory/error_no_holders|id=#{position_id}}}\n"
end
padded_mandates() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 31
def padded_mandates
  [nil, mandates, nil].flatten(1)
end
sparql() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 35
def sparql
  @sparql ||= mandates_query.new(position_id)
end
table_rows() click to toggle source
# File lib/wikidata_position_history/report/mandate.rb, line 51
def table_rows
  padded_mandates.each_cons(3).map do |later, current, earlier|
    {
      mandate: OutputRow::Mandate.new(later, current, earlier),
      bio:     biodata_for(current.officeholder),
    }
  end
end