Class: Aries::Character

Inherits:
Object
  • Object
show all
Defined in:
lib/aries/models/character.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Character



9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#fameObject (readonly)

Returns the value of attribute fame.



7
8
9
# File 'lib/aries/models/character.rb', line 7

def fame
  @fame
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/aries/models/character.rb', line 7

def id
  @id
end

#jobObject (readonly)

Returns the value of attribute job.



7
8
9
# File 'lib/aries/models/character.rb', line 7

def job
  @job
end

#levelObject (readonly)

Returns the value of attribute level.



7
8
9
# File 'lib/aries/models/character.rb', line 7

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/aries/models/character.rb', line 7

def name
  @name
end

#paragonObject (readonly)

Returns the value of attribute paragon.



7
8
9
# File 'lib/aries/models/character.rb', line 7

def paragon
  @paragon
end

#worldObject (readonly)

Returns the value of attribute world.



7
8
9
# File 'lib/aries/models/character.rb', line 7

def world
  @world
end

Class Method Details

.all(n = 1) ⇒ Object



43
44
45
46
# 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) ⇒ Object



48
49
50
51
# 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) ⇒ Object



58
59
60
61
# 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) ⇒ Object



53
54
55
56
# 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

.onlineObject



33
34
35
36
37
38
39
40
41
# 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

Instance Method Details

#to_hashObject



29
30
31
# File 'lib/aries/models/character.rb', line 29

def to_hash
  JSON.parse(to_json, symbolize_names: true)
end

#to_jsonObject



19
20
21
22
23
24
25
26
27
# 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