Class: NHKore::SearchLink

Inherits:
Object
  • Object
show all
Extended by:
AttrBool::Ext
Defined in:
lib/nhkore/search_link.rb

Overview

Author:

  • Jonathan Bradley Whited

Since:

  • 0.2.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, scraped: false) ⇒ SearchLink

Returns a new instance of SearchLink.

Since:

  • 0.2.0



34
35
36
37
38
39
40
41
42
43
# 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

Instance Attribute Details

#datetimeObject

Since:

  • 0.2.0



27
28
29
# File 'lib/nhkore/search_link.rb', line 27

def datetime
  @datetime
end

#futsuurlObject

Since:

  • 0.2.0



28
29
30
# File 'lib/nhkore/search_link.rb', line 28

def futsuurl
  @futsuurl
end

#sha256Object

Since:

  • 0.2.0



30
31
32
# File 'lib/nhkore/search_link.rb', line 30

def sha256
  @sha256
end

#titleObject

Since:

  • 0.2.0



31
32
33
# File 'lib/nhkore/search_link.rb', line 31

def title
  @title
end

#urlObject

Since:

  • 0.2.0



32
33
34
# File 'lib/nhkore/search_link.rb', line 32

def url
  @url
end

Class Method Details

.load_data(key, hash) ⇒ Object

Since:

  • 0.2.0



56
57
58
59
60
61
62
63
64
65
66
67
68
# 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

Instance Method Details

#encode_with(coder) ⇒ Object

Since:

  • 0.2.0



45
46
47
48
49
50
51
52
53
54
# 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

#to_s(mini: false) ⇒ Object

Since:

  • 0.2.0



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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) ⇒ Object

Since:

  • 0.2.0



70
71
72
73
74
75
76
77
78
# 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