Sha256: b8e0f61a6e43c888fad555eb81022d02a3c2df58e7564585eb27207ff40b94af

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

module QuakeliveApi
  module Parser
    class Awards < Base

      def earned
        awards = document.css(selector(:earned))
        if awards
          awards.map { |node| parse_node(node) }
        end
      end

      def unearned
        document.css(selector(:unearned)).map { |node| parse_node(node) }
      end

      private

      def selectors
        {
          earned:   ".detailArea",
          unearned: ".detailArea_off"
        }
      end

      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

      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
    end

    class CareerMilestones < Awards; end
    class Experience       < Awards; end
    class MadSkillz        < Awards; end
    class SocialLife       < Awards; end
    class SweetSuccess     < Awards; end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
quakelive_api-0.1.2 lib/quakelive_api/parser/awards.rb
quakelive_api-0.1.1 lib/quakelive_api/parser/awards.rb
quakelive_api-0.1.0 lib/quakelive_api/parser/awards.rb