2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-05-21 20:03:46 +00:00
|
|
|
class SlugNonprofitNamingAlgorithm < CopyNamingAlgorithm
|
2019-07-30 21:29:24 +00:00
|
|
|
attr_accessor :state_slug, :city_slug
|
2018-05-21 20:03:46 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def initialize(state_slug, city_slug)
|
|
|
|
@state_slug = state_slug
|
|
|
|
@city_slug = city_slug
|
2018-05-21 20:03:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def copy_addition
|
2019-07-30 21:29:24 +00:00
|
|
|
''
|
2018-05-21 20:03:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def max_copies
|
|
|
|
99
|
|
|
|
end
|
|
|
|
|
|
|
|
def separator_before_copy_number
|
|
|
|
'-'
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_name_for_entity(name_entity)
|
|
|
|
name_entity.slug
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_already_used_name_entities(base_name)
|
2019-07-30 21:29:24 +00:00
|
|
|
end_name = '\\-\\d{2}'
|
|
|
|
Nonprofit.method(:where).call('slug SIMILAR TO ? AND state_code_slug = ? AND city_slug = ?', base_name + end_name, @state_slug, @city_slug).select('slug')
|
2018-05-21 20:03:46 +00:00
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|