Sha256: 3e391ead05db1607fa391b981ebc994c29e4d2bf780027da216eb501de0abda7

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Sportradar
  module Api
    class Content::Article < Data
      attr_accessor :response, :type, :created, :updated, :injury, :transaction, :title, :byline, :dateline, :credit, :content, :references, :provider

      def initialize(data)
        @response = data
        @created = Time.parse(data["created"]) if data["created"]
        @updated = Time.parse(data["updated"]) if data["updated"]
        @type = data["type"]
        @injury = data["injury"]
        @transaction = data["transaction"]
        @title = data["title"]
        @byline = data["byline"]
        @dateline = data["dateline"]
        @credit = data["credit"]
        @content = data["content"]["long"] if data["content"] && data["content"]["long"]
        @provider = OpenStruct.new(data["provider"]) if data["provider"]
        set_references
      end

      def transaction?
        transaction == 'true'
      end

      def injury?
        injury == 'true'
      end

      private
      def set_references
        if response["refs"] && response["refs"]["ref"]
          if response["refs"]["ref"].is_a?(Array)
            @references = response["refs"]["ref"].map {|x| Sportradar::Api::Content::Reference.new x }
          elsif response["refs"]["ref"].is_a?(Hash)
            @references = [ Sportradar::Api::Content::Reference.new(response["refs"]["ref"]) ]
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sportradar-api-0.1.38 lib/sportradar/api/content/article.rb