Sha256: f3c3e47fd091a66c999c4a40c23a81065703dfc3efd4bbcf43bf9192a8fd78b9

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

require 'actv/asset'
require 'active_support/core_ext/object/blank'

module ACTV
  class Author < Asset
    def self.build_from_article article_hash
      new article_hash
    end

    def self.valid? response
      ACTV::AuthorValidator.new(response).valid?
    end

    def name
      name_from_footer.presence || self.author_name.presence
    end

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

    def bio
      @bio ||= begin
        bio_node = from_footer 'div.author-text'
        bio_node.inner_html unless bio_node.nil?
      end
    end

    def photo
      @photo ||= begin
        image_node = from_footer 'div.signature-block-photo img'
        if image_node
          url = image_node.attribute('src').to_s
          ACTV::AssetImage.new imageUrlAdr: url
        end
      end
    end

    def image_url
      if photo.url && photo.url.start_with?("/")
        "https://www.active.com#{photo.url}"
      else
        photo.url
      end
    end

    def name_from_footer
      @name_from_footer ||= begin
        name_node = from_footer 'span.author-name'
        name_node.text unless name_node.nil?
      end
    end

    private

    def from_footer selector
      if footer.present?
        doc = Nokogiri::HTML footer
        doc.css(selector).first
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
actv-2.10.9 lib/actv/author.rb
actv-2.10.8 lib/actv/author.rb
actv-2.10.7 lib/actv/author.rb
actv-2.10.6 lib/actv/author.rb