Sha256: 8f32cdc4cd4ce2ef5d160f134f47b07e5ff89cbd171f77c37799c81c9d6e322d

Contents?: true

Size: 1.29 KB

Versions: 24

Compression:

Stored size: 1.29 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?("/")
        "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

24 entries across 24 versions & 1 rubygems

Version Path
actv-2.10.5 lib/actv/author.rb
actv-2.10.4 lib/actv/author.rb
actv-2.10.3 lib/actv/author.rb
actv-2.10.2 lib/actv/author.rb
actv-2.10.1 lib/actv/author.rb
actv-2.10.0 lib/actv/author.rb
actv-2.9.2 lib/actv/author.rb
actv-2.9.1 lib/actv/author.rb
actv-2.9.0 lib/actv/author.rb
actv-2.8.2 lib/actv/author.rb
actv-2.8.1 lib/actv/author.rb
actv-2.7.0 lib/actv/author.rb
actv-2.6.0 lib/actv/author.rb
actv-2.5.2 lib/actv/author.rb
actv-2.5.1 lib/actv/author.rb
actv-2.5.0 lib/actv/author.rb
actv-2.4.0 lib/actv/author.rb
actv-2.3.0 lib/actv/author.rb
actv-2.2.1 lib/actv/author.rb
actv-2.2.0 lib/actv/author.rb