Class: FFXIV::Lodestone::Linkshell
- Defined in:
- lib/ffxiv/lodestone/linkshell.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#members(verbose = false) ⇒ Object
Returns the value of attribute members.
-
#name ⇒ Object
Returns the value of attribute name.
-
#num_members ⇒ Object
Returns the value of attribute num_members.
-
#server ⇒ Object
Returns the value of attribute server.
Class Method Summary collapse
- .find_by_id(id) ⇒ Object
- .name_to_id(name, server) ⇒ Object
- .search(keyword, server: nil, page: 1, verbose: false) ⇒ Object
Methods inherited from Model
#attributes, find_by_name, #initialize
Constructor Details
This class inherits a constructor from FFXIV::Lodestone::Model
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 5 def id @id end |
#members(verbose = false) ⇒ Object
Returns the value of attribute members.
5 6 7 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 5 def members @members end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 5 def name @name end |
#num_members ⇒ Object
Returns the value of attribute num_members.
5 6 7 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 5 def num_members @num_members end |
#server ⇒ Object
Returns the value of attribute server.
5 6 7 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 5 def server @server end |
Class Method Details
.find_by_id(id) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 49 def find_by_id(id) begin dom = Lodestone.fetch("linkshell/#{id}") props = {} props[:id] = id buff = dom.at("div.contents_header h2").content.match(/^(.+)\s\((.+)\)$/) props[:name] = buff[1] props[:server] = buff[2] props[:num_members] = dom.at("h3.ic_silver").content.match(/\s\((\d+)\s/)[1].to_i self.new(props) rescue => e pp e nil end end |
.name_to_id(name, server) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 39 def name_to_id(name, server) search_results = self.search(name, server: server) if search_results search_results[:linkshells].each do |ls| return ls.id if name.downcase == ls.name.downcase end end nil end |
.search(keyword, server: nil, page: 1, verbose: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ffxiv/lodestone/linkshell.rb', line 9 def search(keyword, server: nil, page: 1, verbose: false) dom = Lodestone.fetch("linkshell/?q=#{URI.escape(keyword)}&worldname=#{URI.escape(server)}&page=#{URI.escape(page.to_s)}") linkshells = dom.search("table.table_elements_com_ls tr").map do |tr| h4 = tr.at("th h4") a = h4.at("a") id = a.attr("href").split("/")[-1].to_i if verbose self.find_by_id(id) else self.new({ id: id, name: a.content, server: h4.at("span").content.strip[1...-1], num_members: tr.at("td span").content.split(": ")[1].to_i }) end end pagination = dom.at("div.current_list") if pagination total = pagination.at("span.total").content.to_i results = { show_start: pagination.at("span.show_start").content.to_i, show_end: pagination.at("span.show_end").content.to_i, total: total, num_pages: (total / 50.0).ceil, linkshells: linkshells } end end |