Module: Parliament::Utils::Helpers::HousesHelper

Defined in:
lib/parliament/utils/helpers/houses_helper.rb

Class Method Summary collapse

Class Method Details

.commons?(house) ⇒ Boolean

Checks if house is the House of Commons and sets @commons_id and @lords_id if not already set.



10
11
12
13
14
# File 'lib/parliament/utils/helpers/houses_helper.rb', line 10

def commons?(house)
  set_ids

  house.graph_id == @commons_id
end

.commons_idString

Sets and returns the id for the House of Commons.



27
28
29
30
31
# File 'lib/parliament/utils/helpers/houses_helper.rb', line 27

def commons_id
  set_ids

  @commons_id
end

.house_id_string(house) ⇒ Array<String, String>

Returns the current house id for the page alongside the other house id.



46
47
48
49
50
51
52
53
# File 'lib/parliament/utils/helpers/houses_helper.rb', line 46

def house_id_string(house)
  is_commons = commons?(house)

  house_ids = [commons_id, lords_id]
  return house_ids if is_commons

  house_ids.reverse
end

.lords?(house) ⇒ Boolean

Checks if house is the House of Lords and sets @commons_id and @lords_id if not already set.



20
21
22
# File 'lib/parliament/utils/helpers/houses_helper.rb', line 20

def lords?(house)
  !commons?(house)
end

.lords_idString

Sets and returns the id for the House of Lords.



36
37
38
39
40
# File 'lib/parliament/utils/helpers/houses_helper.rb', line 36

def lords_id
  set_ids

  @lords_id
end

.person_type_string(house) ⇒ Array<String, String>

Returns the current



59
60
61
62
63
64
65
66
67
# File 'lib/parliament/utils/helpers/houses_helper.rb', line 59

def person_type_string(house)
  is_mp = commons?(house)

  types = [I18n.t('mp_plural'), I18n.t('lord_plural')]

  return types if is_mp

  types.reverse
end

.set_idsObject



71
72
73
74
75
76
77
# File 'lib/parliament/utils/helpers/houses_helper.rb', line 71

def set_ids
  return if @commons_id && @lords_id
  houses = Parliament::Utils::Helpers::ParliamentHelper.parliament_request.house_index.get.filter('https://id.parliament.uk/schema/House').sort_by(:name)

  @commons_id = houses.first.graph_id
  @lords_id = houses.last.graph_id
end