Sha256: 51241350bc8eb9a8f5c5d5645df631879e661160a534699c99befdaffc41ffda

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 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'
        url = image_node.attribute('src').to_s
        ACTV::AssetImage.new imageUrlAdr: url
      end
    end

    def image_url
      if photo.url && photo.url.start_with?("/")
        "http://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

3 entries across 3 versions & 1 rubygems

Version Path
actv-1.4.2 lib/actv/author.rb
actv-1.4.1 lib/actv/author.rb
actv-1.4.0 lib/actv/author.rb