lib/parliament/utils/helpers/houses_helper.rb in parliament-utils-0.8.4 vs lib/parliament/utils/helpers/houses_helper.rb in parliament-utils-0.8.5

- old
+ new

@@ -1,79 +1,81 @@ module Parliament module Utils module Helpers module HousesHelper - # Checks if house is the House of Commons and sets @commons_id and @lords_id if not already set. - # - # @param [Grom::Node] house a Grom::Node with type https://id.parliament.uk/schema/House. - # @return [Boolean] boolean depending on whether the house has the same id as the House of Commons. - def self.commons?(house) - set_ids + class << self + # Checks if house is the House of Commons and sets @commons_id and @lords_id if not already set. + # + # @param [Grom::Node] house a Grom::Node with type https://id.parliament.uk/schema/House. + # @return [Boolean] boolean depending on whether the house has the same id as the House of Commons. + def commons?(house) + set_ids - house.graph_id == @commons_id - end + house.graph_id == @commons_id + end - # Checks if house is the House of Lords and sets @commons_id and @lords_id if not already set. - # - # @param [Grom::Node] house a Grom::Node with type https://id.parliament.uk/schema/House. - # @return [Boolean] boolean depending on whether the house has the same id as the House of Lords. - def self.lords?(house) - !commons?(house) - end + # Checks if house is the House of Lords and sets @commons_id and @lords_id if not already set. + # + # @param [Grom::Node] house a Grom::Node with type https://id.parliament.uk/schema/House. + # @return [Boolean] boolean depending on whether the house has the same id as the House of Lords. + def lords?(house) + !commons?(house) + end - # Sets and returns the id for the House of Commons. - # - # @return [String] @commons_id the id for the House of Commons. - def self.commons_id - set_ids + # Sets and returns the id for the House of Commons. + # + # @return [String] @commons_id the id for the House of Commons. + def commons_id + set_ids - @commons_id - end + @commons_id + end - # Sets and returns the id for the House of Lords. - # - # @return [String] @lords_id the id for the House of Lords. - def self.lords_id - set_ids + # Sets and returns the id for the House of Lords. + # + # @return [String] @lords_id the id for the House of Lords. + def lords_id + set_ids - @lords_id - end + @lords_id + end - # Returns the current house id for the page alongside the other house id. - # - # @param [Grom::Node] house The house that a particular person is linked to. - # @return [Array<String, String>] The current house id and other house id. - def self.house_id_string(house) - is_commons = self.commons?(house) + # Returns the current house id for the page alongside the other house id. + # + # @param [Grom::Node] house The house that a particular person is linked to. + # @return [Array<String, String>] The current house id and other house id. + def house_id_string(house) + is_commons = commons?(house) - house_ids = [commons_id, lords_id] - return house_ids if is_commons + house_ids = [commons_id, lords_id] + return house_ids if is_commons - house_ids.reverse - end + house_ids.reverse + end - # Returns the current - # - # @param [Grom::Node] house The house that a particular person is linked to. - # @return [Array<String, String>] The current person type and other person type. - def self.person_type_string(house) - is_mp = self.commons?(house) + # Returns the current + # + # @param [Grom::Node] house The house that a particular person is linked to. + # @return [Array<String, String>] The current person type and other person type. + def person_type_string(house) + is_mp = commons?(house) - types = [I18n.t('mp_plural'), I18n.t('lord_plural')] + types = [I18n.t('mp_plural'), I18n.t('lord_plural')] - return types if is_mp + return types if is_mp - types.reverse - end + types.reverse + end - private_class_method + private_class_method - def self.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) + 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 + @commons_id = houses.first.graph_id + @lords_id = houses.last.graph_id + end end end end end end