Sha256: 06629685d52f15f4c4be1fb05174866026f5b82b8305ed4b09dfd968be057cd9

Contents?: true

Size: 1.78 KB

Versions: 6

Compression:

Stored size: 1.78 KB

Contents

require 'actv/asset'
require 'nokogiri'

module ACTV
  class Article < ACTV::Asset

    def author_footer
      @author_footer ||= description_by_type 'authorFooter'
    end

    def by_line
      @author ||= description_by_type 'articleByLine'
    end

    def author_bio
      @author_bio ||= begin
        bio_node = get_from_author_footer('div.author-text')
        bio_node.inner_html unless bio_node.nil?
      end
    end

    def author_photo
      @author_photo ||= begin
        image = nil

        image_node = get_from_author_footer('div.signature-block-photo img')
        if !image_node.nil?
          image = ACTV::AssetImage.new({imageUrlAdr: image_node.attribute('src').text}) if image_node.attribute 'src'
        end

        image
      end
    end

    def author_name_from_footer
      @author_name_from_footer ||= begin
        name_node = get_from_author_footer('span.author-name')
        name_node.text unless name_node.nil?
      end
    end

    def source
      @source ||= description_by_type 'articleSource'
    end

    def type
      @type ||= tag_by_description 'articleType'
    end

    def image
      @image ||= image_by_name 'image2'
    end

    def subtitle
      @subtitle ||= description_by_type 'subtitle'
    end

    def footer
      @footer ||= description_by_type 'footer'
    end

    def inline_ad
      @inline_ad ||= begin
        val = tag_by_description 'inlinead'
        if val
          val.downcase == 'true'
        else
          true
        end
      end
    end
    alias inline_ad? inline_ad

    private

      def get_from_author_footer(selector)
        node = nil

        if !author_footer.nil? && !author_footer.empty?
          doc = Nokogiri::HTML(author_footer)
          node = doc.css(selector).first
        end

        node
      end
  end
end


Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
actv-1.1.17 lib/actv/article.rb
actv-1.1.6 lib/actv/article.rb
actv-1.1.5 lib/actv/article.rb
actv-1.1.3 lib/actv/article.rb
actv-1.1.1 lib/actv/article.rb
actv-1.1.0 lib/actv/article.rb