Class: Holidays::Definition::Repository::Regions

Inherits:
Object
  • Object
show all
Defined in:
lib/holidays/definition/repository/regions.rb

Instance Method Summary collapse

Constructor Details

#initialize(all_generated_regions, parent_region_lookup) ⇒ Regions

Returns a new instance of Regions.



5
6
7
8
9
# File 'lib/holidays/definition/repository/regions.rb', line 5

def initialize(all_generated_regions, parent_region_lookup)
  @loaded_regions = []
  @all_generated_regions = all_generated_regions
  @parent_region_lookup = parent_region_lookup
end

Instance Method Details

#add(regions) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/holidays/definition/repository/regions.rb', line 28

def add(regions)
  regions = [regions] unless regions.is_a?(Array)

  regions.each do |region|
    raise ArgumentError unless region.is_a?(Symbol)
  end

  @loaded_regions = @loaded_regions | regions
  @loaded_regions.uniq!
end

#all_generatedObject



11
12
13
# File 'lib/holidays/definition/repository/regions.rb', line 11

def all_generated
  @all_generated_regions
end

#all_loadedObject



19
20
21
# File 'lib/holidays/definition/repository/regions.rb', line 19

def all_loaded
  @loaded_regions
end

#loaded?(region) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


23
24
25
26
# File 'lib/holidays/definition/repository/regions.rb', line 23

def loaded?(region)
  raise ArgumentError unless region.is_a?(Symbol)
  @loaded_regions.include?(region)
end

#parent_region_lookup(r) ⇒ Object



15
16
17
# File 'lib/holidays/definition/repository/regions.rb', line 15

def parent_region_lookup(r)
  @parent_region_lookup[r]
end

#search(prefix) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
# File 'lib/holidays/definition/repository/regions.rb', line 39

def search(prefix)
  raise ArgumentError unless prefix.is_a?(Symbol)
  @loaded_regions.select { |region| region.to_s =~ Regexp.new("^#{prefix}") }
end