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.

Parameters:

Returns:

  • (Boolean)

    boolean depending on whether the house has the same id as the House of Commons.



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.

Returns:

  • (String)

    @commons_id the id for the House of Commons.



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

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.

Parameters:

  • house (Grom::Node)

    The house that a particular person is linked to.

Returns:

  • (Array<String, String>)

    The current house id and other house id.



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

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.

Parameters:

Returns:

  • (Boolean)

    boolean depending on whether the house has the same id as the House of Lords.



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

def lords?(house)
  return false if house.nil?

  !commons?(house)
end

.lords_idString

Sets and returns the id for the House of Lords.

Returns:

  • (String)

    @lords_id the id for the House of Lords.



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

def lords_id
  set_ids

  @lords_id
end

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

Returns the current

Parameters:

  • house (Grom::Node)

    The house that a particular person is linked to.

Returns:

  • (Array<String, String>)

    The current person type and other person type.



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

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



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

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