Class: Aries::Character
- Inherits:
-
Object
- Object
- Aries::Character
- Defined in:
- lib/aries/models/character.rb
Instance Attribute Summary collapse
-
#fame ⇒ Object
readonly
Returns the value of attribute fame.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#paragon ⇒ Object
readonly
Returns the value of attribute paragon.
-
#world ⇒ Object
readonly
Returns the value of attribute world.
Class Method Summary collapse
- .all(n = 1) ⇒ Object
- .fame(n = 1) ⇒ Object
- .find(ign) ⇒ Object
- .job(name, n = 1) ⇒ Object
- .online ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Character
constructor
A new instance of Character.
- #to_hash ⇒ Object
- #to_json ⇒ Object
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
#fame ⇒ Object (readonly)
Returns the value of attribute fame.
7 8 9 |
# File 'lib/aries/models/character.rb', line 7 def fame @fame end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/aries/models/character.rb', line 7 def id @id end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
7 8 9 |
# File 'lib/aries/models/character.rb', line 7 def job @job end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
7 8 9 |
# File 'lib/aries/models/character.rb', line 7 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/aries/models/character.rb', line 7 def name @name end |
#paragon ⇒ Object (readonly)
Returns the value of attribute paragon.
7 8 9 |
# File 'lib/aries/models/character.rb', line 7 def paragon @paragon end |
#world ⇒ Object (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 |
.online ⇒ Object
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_hash ⇒ Object
29 30 31 |
# File 'lib/aries/models/character.rb', line 29 def to_hash JSON.parse(to_json, symbolize_names: true) end |
#to_json ⇒ Object
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 |