class Aries::Character

Attributes

fame[R]
id[R]
job[R]
level[R]
name[R]
paragon[R]
world[R]

Public Class Methods

all(n = 1) click to toggle source
# File lib/aries/models/character.rb, line 43
def self.all(n = 1)
  Aries::Scraper.get(page: 'ranking', overall: skip(n))
                .map { |attr| new(attr) }
end
fame(n = 1) click to toggle source
# File lib/aries/models/character.rb, line 48
def self.fame(n = 1)
  Aries::Scraper.get(page: 'ranking', fame: 1, start: skip(n))
                .map { |attr| new(attr) }
end
find(ign) click to toggle source
# File lib/aries/models/character.rb, line 58
def self.find(ign)
  new Aries::Scraper.post({ page: 'ranking', name: 1 }, username: ign)
                    .first
end
job(name, n = 1) click to toggle source
# File lib/aries/models/character.rb, line 53
def self.job(name, n = 1)
  Aries::Scraper.get(page: 'ranking', job: job_id(name), start: skip(n))
                .map { |attr| new(attr) }
end
new(attributes) click to toggle source
# File lib/aries/models/character.rb, line 9
def initialize(attributes)
  @id      = attributes[:id]
  @name    = attributes[:name]
  @job     = attributes[:job]
  @world   = attributes[:world] || 'Scania'
  @level   = attributes[:level]
  @paragon = attributes[:paragon]
  @fame    = attributes[:fame]
end
online() click to toggle source
# File lib/aries/models/character.rb, line 33
def self.online
  online = Aries::Scraper.raw(page: 'home')
                         .body
                         .match(/(\d+)\sONLINE/)

  return false unless online

  online.captures.first.to_i
end

Protected Class Methods

job_id(name) click to toggle source
# File lib/aries/models/character.rb, line 72
def job_id(name)
  file = File.read \
    File.expand_path('../../../../data/classes.json', __FILE__)
  job = JSON.parse(file).find { |j| j['name'] == name }

  raise Aries::Exception::InvalidJobError, 'Invalid job' if job.nil?

  job['id']
end
skip(page) click to toggle source

HACK: Pagination Skip <number> of characters

# File lib/aries/models/character.rb, line 68
def skip(page)
  (page * 10) - 10
end

Public Instance Methods

to_hash() click to toggle source
# File lib/aries/models/character.rb, line 29
def to_hash
  JSON.parse(to_json, symbolize_names: true)
end
to_json() click to toggle source
# File lib/aries/models/character.rb, line 19
def to_json
  hash = {}
  instance_variables.each do |var|
    var = var[1..-1]
    hash[var] = send(var.to_sym)
  end

  JSON.pretty_generate(hash)
end