Class: Reality::Country::List

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/reality/country.rb

Instance Method Summary collapse

Constructor Details

#initialize(*names) ⇒ List

Returns a new instance of List.



7
8
9
# File 'lib/reality/country.rb', line 7

def initialize(*names)
  @names = names
end

Instance Method Details

#countObject



11
12
13
# File 'lib/reality/country.rb', line 11

def count
  @names.count
end

#each(&block) ⇒ Object



30
31
32
33
# File 'lib/reality/country.rb', line 30

def each(&block)
  @pages = get(*@names)
  @pages.each(&block)
end

#first(n = nil) ⇒ Object



15
16
17
18
# File 'lib/reality/country.rb', line 15

def first(n = nil)
  res = get(*@names.first(n || 1))
  n ? res : res.first
end

#last(n = nil) ⇒ Object



20
21
22
23
# File 'lib/reality/country.rb', line 20

def last(n = nil)
  res = get(*@names.last(n || 1))
  n ? res : res.first
end

#sample(n = nil) ⇒ Object



25
26
27
28
# File 'lib/reality/country.rb', line 25

def sample(n = nil)
  res = get(*@names.sample(n || 1))
  n ? res : res.first
end

#to_aObject



37
38
39
# File 'lib/reality/country.rb', line 37

def to_a
  get(*@names)
end

#where(**filters) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/reality/country.rb', line 41

def where(**filters)
  names = @names & Reality::Country.
    by_continents.
    select{|k, v| v == filters[:continent]}.
    map(&:first)
    
  self.class.new(*names)
end