Class: KenpoApi::Service

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group:, name:, path:) ⇒ Service

Returns a new instance of Service.



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

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

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



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

def group
  @group
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.find(service_group, name) ⇒ Object



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

def self.find(service_group, name)
  self.list(service_group).find { |service| service.name == name }
end

.list(service_group) ⇒ Object



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

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