Class: WikidataPositionHistory::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/wikidata_position_history/report.rb

Overview

The entire wikitext generated for this report

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position_id, template_class = ReportTemplate) ⇒ Report

Returns a new instance of Report.



114
115
116
117
# File 'lib/wikidata_position_history/report.rb', line 114

def initialize(position_id, template_class = ReportTemplate)
  @position_id = position_id
  @template_class = template_class
end

Instance Attribute Details

#position_idObject (readonly)

Returns the value of attribute position_id.



119
120
121
# File 'lib/wikidata_position_history/report.rb', line 119

def position_id
  @position_id
end

#template_classObject (readonly)

Returns the value of attribute template_class.



119
120
121
# File 'lib/wikidata_position_history/report.rb', line 119

def template_class
  @template_class
end

Instance Method Details

#headerObject



128
129
130
# File 'lib/wikidata_position_history/report.rb', line 128

def header
  "== {{Q|#{position_id}}} officeholders #{position_dates} =="
end

#position_datesObject



132
133
134
135
136
137
# File 'lib/wikidata_position_history/report.rb', line 132

def position_dates
  dates = [.inception_date, .abolition_date]
  return '' if dates.compact.empty?

  format('(%s)', dates.join(' – '))
end

#template_paramsObject



143
144
145
146
147
148
149
# File 'lib/wikidata_position_history/report.rb', line 143

def template_params
  {
    metadata:   ,
    table_rows: table_rows,
    sparql_url: sparql.wdqs_url,
  }
end

#wikitextObject



121
122
123
124
125
126
# File 'lib/wikidata_position_history/report.rb', line 121

def wikitext
  return legislator_template if .legislator?
  return no_items_output if mandates.empty?

  template_class.new(template_params).output
end

#wikitext_with_headerObject



139
140
141
# File 'lib/wikidata_position_history/report.rb', line 139

def wikitext_with_header
  [header, wikitext].join("\n")
end