Class: NHKore::SearchLink
- Inherits:
-
Object
- Object
- NHKore::SearchLink
- Extended by:
- AttrBool::Ext
- Defined in:
- lib/nhkore/search_link.rb
Overview
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #encode_with(coder) ⇒ Object
-
#initialize(url, scraped: false) ⇒ SearchLink
constructor
A new instance of SearchLink.
- #to_s(mini: false) ⇒ Object
- #update_from_article(article) ⇒ Object
Constructor Details
#initialize(url, scraped: false) ⇒ SearchLink
Returns a new instance of SearchLink.
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
#datetime ⇒ Object
27 28 29 |
# File 'lib/nhkore/search_link.rb', line 27 def datetime @datetime end |
#futsuurl ⇒ Object
28 29 30 |
# File 'lib/nhkore/search_link.rb', line 28 def futsuurl @futsuurl end |
#sha256 ⇒ Object
30 31 32 |
# File 'lib/nhkore/search_link.rb', line 30 def sha256 @sha256 end |
#title ⇒ Object
31 32 33 |
# File 'lib/nhkore/search_link.rb', line 31 def title @title end |
#url ⇒ Object
32 33 34 |
# File 'lib/nhkore/search_link.rb', line 32 def url @url end |
Class Method Details
.load_data(key, hash) ⇒ Object
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
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
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
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 |