Sha256: 5266a386708d22b89e2eb93f105a00cf677728a066f55e2594913a2d0d52ddd3

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

require 'xiv_lodestone/lodestone_helper'
require 'json'

module XIVLodestone
  # This is a basic class fetchs the server status from
  # lodestone.
  class ServerStatus
    Server = Struct.new(:name, :status, :registration)

    def initialize()
      @list = {}
      fetch_server_status(Helper.open_server_status)
    end
    # Generates methods from @server hash keys
    def method_missing(method)
      return @list[method] if @list.key?(method)
      super
    end
    # Fills the @server hash with each servers status
    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
    # Returns a JSON string of server list
    def to_json
      @list.to_json
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xiv_lodestone-0.0.5 lib/xiv_lodestone/lodestone_server.rb