class NHKore::SearchLink

@author Jonathan Bradley Whited @since 0.2.0

Attributes

datetime[R]
futsuurl[R]
sha256[RW]
title[RW]
url[R]

Public Class Methods

load_data(key,hash) click to toggle source
# File lib/nhkore/search_link.rb, line 56
def self.load_data(key,hash)
  slink = SearchLink.new(
    hash[:url],
    scraped: hash[:scraped],
  )

  slink.datetime = hash[:datetime]
  slink.futsuurl = hash[:futsuurl]
  slink.sha256 = hash[:sha256]
  slink.title = hash[:title]

  return slink
end
new(url,scraped: false) click to toggle source
Calls superclass method
# File lib/nhkore/search_link.rb, line 34
def initialize(url,scraped: false)
  super()

  @datetime = nil
  @futsuurl = nil
  @scraped = scraped
  @sha256 = sha256
  @title = nil
  self.url = url
end

Public Instance Methods

datetime=(value) click to toggle source
# File lib/nhkore/search_link.rb, line 80
def datetime=(value)
  if value.is_a?(Time)
    @datetime = value
  else
    @datetime = Util.empty_web_str?(value) ? nil : Time.iso8601(value)
  end
end
encode_with(coder) click to toggle source
# File lib/nhkore/search_link.rb, line 45
def encode_with(coder)
  # Order matters.

  coder[:url] = @url.nil? ? nil : @url.to_s
  coder[:scraped] = @scraped
  coder[:datetime] = @datetime.nil? ? nil : @datetime.iso8601
  coder[:title] = @title
  coder[:futsuurl] = @futsuurl.nil? ? nil : @futsuurl.to_s
  coder[:sha256] = @sha256
end
futsuurl=(value) click to toggle source
# File lib/nhkore/search_link.rb, line 88
def futsuurl=(value)
  # Don't store URI, store String.
  @futsuurl = value.nil? ? nil : value.to_s
end
to_s(mini: false) click to toggle source
# File lib/nhkore/search_link.rb, line 98
def to_s(mini: false)
  s = ''.dup

  s << "'#{@url}': "

  if mini
    s << "{ scraped? #{@scraped ? 'yes' : 'NO'} }"
  else
    s << "\n  scraped?  #{@scraped ? 'yes' : 'NO'}"
    s << "\n  datetime: '#{@datetime}'"
    s << "\n  title:    '#{@title}'"
    s << "\n  futsuurl: '#{@futsuurl}'"
    s << "\n  sha256:   '#{@sha256}'"
  end

  return s
end
update_from_article(article) click to toggle source
# File lib/nhkore/search_link.rb, line 70
def update_from_article(article)
  # Don't update the url, as it may be different (e.g., http vs https).

  self.datetime = article.datetime if @datetime.nil?
  self.futsuurl = article.futsuurl if Util.empty_web_str?(@futsuurl)
  @scraped = true # If we have an article, it's been scraped
  @sha256 = article.sha256 if Util.empty_web_str?(@sha256)
  @title = article.title if Util.empty_web_str?(@title)
end
url=(value) click to toggle source
# File lib/nhkore/search_link.rb, line 93
def url=(value)
  # Don't store URI, store String.
  @url = value.nil? ? nil : value.to_s
end