Sha256: 1840cccc776d83acad534dcf8bce184a938e010006636b8f84a84c4fc35e22f7

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module FootStats
  class Live < Resource
    class Team
      attr_reader :coach, :full_name, :source_id
      attr_reader :cards, :players, :goals

      def initialize(params)
        @coach     = params['@Tecnico']
        @full_name = params['@Nome']
        @source_id = params['@Id']

        parse_cards   params['Cartoes']
        parse_goals   params['Gols']
        parse_players params['Escalacao']
      end

      def initial_players
        players.find_all{ |player| !player.substituted? }
      end

      def substituted_players
        players.find_all{ |player| player.substituted? }
      end

      protected
      def fix_collection(collection, key)
        return [] if collection.nil?

        if collection[key].is_a? Array
          collection[key]
        else
          [ collection[key] ]
        end
      end

      def parse_goals(goals)
        @goals = fix_collection(goals, 'Gol').map do |goal_params|
          Goal.new goal_params
        end
      end

      def parse_cards(cards)
        @cards = fix_collection(cards, 'Cartoes').map do |card_params|
          Card.new card_params
        end
      end

      def parse_players(players)
        @players = fix_collection(players, 'Jogador').map do |player_params|
          Player.new player_params
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foot_stats-0.1.0 lib/foot_stats/live_team.rb