Class: XIVLodestone::ServerStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/xiv_lodestone/lodestone_server.rb

Overview

This is a basic class fetchs the server status from lodestone.

Defined Under Namespace

Classes: Server

Instance Method Summary collapse

Constructor Details

#initializeServerStatus

Returns a new instance of ServerStatus.



10
11
12
13
# File 'lib/xiv_lodestone/lodestone_server.rb', line 10

def initialize()
  @list = {}
  fetch_server_status(Helper.open_server_status)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

Generates methods from @server hash keys



15
16
17
18
# File 'lib/xiv_lodestone/lodestone_server.rb', line 15

def method_missing(method)
  return @list[method] if @list.key?(method)
  super
end

Instance Method Details

#fetch_server_status(page) ⇒ Object

Fills the @server hash with each servers status



20
21
22
23
24
25
26
27
28
# File 'lib/xiv_lodestone/lodestone_server.rb', line 20

def fetch_server_status(page)
  rego = Helper.open_registration_status
  page.xpath('//td').each_slice(2) do |elem|
    @list[elem[0].text.strip.downcase.to_sym] = Server.new(
      elem[0].text.strip,
      elem[1].text.strip,
      rego.css('div.area_inner_cont').text[/#{elem[0].text.strip}/] ? "Open" : "Closed")
  end
end

#to_jsonObject

Returns a JSON string of server list



30
31
32
# File 'lib/xiv_lodestone/lodestone_server.rb', line 30

def to_json
  @list.to_json
end