class QuakeliveApi::Parser::Awards

Public Instance Methods

earned() click to toggle source
# File lib/quakelive_api/parser/awards.rb, line 5
def earned
  awards = document.css(selector(:earned))
  if awards
    awards.map { |node| parse_node(node) }
  end
end
unearned() click to toggle source
# File lib/quakelive_api/parser/awards.rb, line 12
def unearned
  document.css(selector(:unearned)).map { |node| parse_node(node) }
end

Private Instance Methods

awarded_at(node) click to toggle source
# File lib/quakelive_api/parser/awards.rb, line 36
def awarded_at(node)
  return unless node.css('ul.fl li').count >= 3

  matches = node.at('ul.fl li:first-child').content.match(/(\d{2})\/(\d{2})\/(\d{4})/)
  Date.new(matches[3].to_i, matches[1].to_i, matches[2].to_i) unless matches.nil?
end
parse_node(node) click to toggle source
# File lib/quakelive_api/parser/awards.rb, line 25
def parse_node(node)
  attrs = {
    icon:        node.at('img')['src'],
    info:        node.at('img')['title'],
    name:        node.at('span.bigRedTxt').content,
    description: node.at('span.blktxt_11').content,
    awarded:     awarded_at(node)
  }
  Items::Award.new(attrs)
end
selectors() click to toggle source
# File lib/quakelive_api/parser/awards.rb, line 18
def selectors
  {
    earned:   ".detailArea",
    unearned: ".detailArea_off"
  }
end