Class: NHKore::SearchLink

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

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.



28
29
30
31
32
33
34
35
36
37
# File 'lib/nhkore/search_link.rb', line 28

def initialize(url,scraped: false)
  super()

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

Instance Attribute Details

#datetimeObject

Returns the value of attribute datetime.



21
22
23
# File 'lib/nhkore/search_link.rb', line 21

def datetime
  @datetime
end

#futsuurlObject

Returns the value of attribute futsuurl.



22
23
24
# File 'lib/nhkore/search_link.rb', line 22

def futsuurl
  @futsuurl
end

#sha256Object

Returns the value of attribute sha256.



24
25
26
# File 'lib/nhkore/search_link.rb', line 24

def sha256
  @sha256
end

#titleObject

Returns the value of attribute title.



25
26
27
# File 'lib/nhkore/search_link.rb', line 25

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.load_data(_key, hash) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nhkore/search_link.rb', line 50

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



39
40
41
42
43
44
45
46
47
48
# File 'lib/nhkore/search_link.rb', line 39

def encode_with(coder)
  # Order matters.

  coder[:url] = @url&.to_s
  coder[:scraped] = @scraped
  coder[:datetime] = @datetime&.iso8601
  coder[:title] = @title
  coder[:futsuurl] = @futsuurl&.to_s
  coder[:sha256] = @sha256
end

#to_s(mini: false) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/nhkore/search_link.rb', line 92

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



64
65
66
67
68
69
70
71
72
# File 'lib/nhkore/search_link.rb', line 64

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