Class: KenpoApi::ServiceGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/kenpo_api/service_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(category:, name:, path:) ⇒ ServiceGroup

Returns a new instance of ServiceGroup.



5
6
7
8
9
# File 'lib/kenpo_api/service_group.rb', line 5

def initialize(category:, name:, path:)
  @category = category
  @name = name
  @path = path
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



3
4
5
# File 'lib/kenpo_api/service_group.rb', line 3

def category
  @category
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/kenpo_api/service_group.rb', line 3

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/kenpo_api/service_group.rb', line 3

def path
  @path
end

Class Method Details

.find(service_category, name) ⇒ Object



22
23
24
# File 'lib/kenpo_api/service_group.rb', line 22

def self.find(service_category, name)
  self.list(service_category).find { |group| group.name == name }
end

.list(service_category) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/kenpo_api/service_group.rb', line 11

def self.list(service_category)
  return [] if service_category.nil?
  Client.instance.fetch_document(path: service_category.path).xpath('//section[@class="request-box"]//a').map do |link|
    self.new(
      category: service_category,
      name: link.text,
      path: link['href'],
    )
  end
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/kenpo_api/service_group.rb', line 34

def available?
  self.services.any?
end

#find_service(name) ⇒ Object



30
31
32
# File 'lib/kenpo_api/service_group.rb', line 30

def find_service(name)
  Service.find(self, name)
end

#servicesObject



26
27
28
# File 'lib/kenpo_api/service_group.rb', line 26

def services
  Service.list(self)
end