nhkore 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1db415fe5fa2d6f112fae3ef163b79ddaa88d639de565c4cb35b40fa14fb5a66
4
- data.tar.gz: c535ba1f719db2c64ba6713c21c6365f51e31361efd6046064cdf700219f30ab
3
+ metadata.gz: cef37a085d0bb5b9143d8cf685729d84a4ec3665954ca6bcbdcf188ee6f43ac5
4
+ data.tar.gz: bf866f3c827b5a2e853133f1f62f71c76d7699df28d0cd838bef9cf5893eb556
5
5
  SHA512:
6
- metadata.gz: af517bada681dc850e60f1c0e275ba35d2177dc413b076612a091217fd653bba82be725c0247c52bb1e342489fe99c731ac7f5efc0b681d54cdcbb02cdb5360b
7
- data.tar.gz: 579569f8c5201f3fe8b460281d585ac8b10c50c881d18ca6d6ff342fab0c178f0ad6e532df42200db117b0f8e85dbbace87846c85fcdd5c0c4eac1501f4b24e7
6
+ metadata.gz: 583c214ed3fb70a8ee7cce7378dba5595060780d55e4111d17ccb39cecffb2aa4ae67ede3c8f8215b52f485ac967c72a96be662ec35f40a75d4ff03cef0c070e
7
+ data.tar.gz: 5ac717084e1e9ea92243e16266dcaa123e01bf066574ee8ae747a196bdc8d9ae96227429843f2a6a09d6a3c849c91d3373109a2657c996a558cd4b4f2954ea17
data/CHANGELOG.md CHANGED
@@ -2,7 +2,17 @@
2
2
 
3
3
  Format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
- ## [[Unreleased]](https://github.com/esotericpig/nhkore/compare/v0.3.4...master)
5
+ ## [[Unreleased]](https://github.com/esotericpig/nhkore/compare/v0.3.5...master)
6
+
7
+ ## [v0.3.5] - 2020-05-04
8
+
9
+ ### Added
10
+ - Added check for environment var `NO_COLOR`
11
+ - [https://no-color.org/](https://no-color.org/)
12
+
13
+ ### Fixed
14
+ - Fixed URLs stored in YAML data to always be of type String (not URI)
15
+ - This initially caused a problem in DictScraper.parse_url() from ArticleScraper, but fixed it for all data
6
16
 
7
17
  ## [v0.3.4] - 2020-04-25
8
18
 
data/lib/nhkore/app.rb CHANGED
@@ -152,7 +152,8 @@ module NHKore
152
152
  end
153
153
 
154
154
  if color.nil?()
155
- color = ($stdout.tty?() && ENV['TERM'] != 'dumb')
155
+ # - https://no-color.org/
156
+ color = ($stdout.tty?() && ENV['TERM'] != 'dumb' && !ENV.key?('NO_COLOR'))
156
157
  end
157
158
 
158
159
  enable_color(color)
@@ -33,11 +33,11 @@ module NHKore
33
33
  # @since 0.2.0
34
34
  ###
35
35
  class Article
36
- attr_accessor :datetime
37
- attr_accessor :futsuurl
36
+ attr_reader :datetime
37
+ attr_reader :futsuurl
38
38
  attr_accessor :sha256
39
39
  attr_accessor :title
40
- attr_accessor :url
40
+ attr_reader :url
41
41
  attr_reader :words
42
42
 
43
43
  def initialize()
@@ -79,19 +79,18 @@ module NHKore
79
79
 
80
80
  coder[:datetime] = @datetime.nil?() ? @datetime : @datetime.iso8601()
81
81
  coder[:title] = @title
82
- coder[:url] = @url
83
- coder[:futsuurl] = @futsuurl
82
+ coder[:url] = @url.nil?() ? nil : @url.to_s()
83
+ coder[:futsuurl] = @futsuurl.nil?() ? nil : @futsuurl.to_s()
84
84
  coder[:sha256] = @sha256
85
85
  coder[:words] = @words
86
86
  end
87
87
 
88
88
  def self.load_data(key,hash)
89
- datetime = hash[:datetime]
90
89
  words = hash[:words]
91
90
 
92
91
  article = Article.new()
93
92
 
94
- article.datetime = Util.empty_web_str?(datetime) ? nil : Time.iso8601(datetime)
93
+ article.datetime = hash[:datetime]
95
94
  article.futsuurl = hash[:futsuurl]
96
95
  article.sha256 = hash[:sha256]
97
96
  article.title = hash[:title]
@@ -107,6 +106,24 @@ module NHKore
107
106
  return article
108
107
  end
109
108
 
109
+ def datetime=(value)
110
+ if value.is_a?(Time)
111
+ @datetime = value
112
+ else
113
+ @datetime = Util.empty_web_str?(value) ? nil : Time.iso8601(value)
114
+ end
115
+ end
116
+
117
+ def futsuurl=(value)
118
+ # Don't store URI, store String.
119
+ @futsuurl = value.nil?() ? nil : value.to_s()
120
+ end
121
+
122
+ def url=(value)
123
+ # Don't store URI, store String.
124
+ @url = value.nil?() ? nil : value.to_s()
125
+ end
126
+
110
127
  def to_s(mini: false)
111
128
  s = ''.dup()
112
129
 
@@ -44,7 +44,7 @@ module NHKore
44
44
  end
45
45
 
46
46
  def self.parse_url(url,basename: nil)
47
- url = Util.strip_web_str(url)
47
+ url = Util.strip_web_str(url.to_s())
48
48
 
49
49
  raise ParseError,"cannot parse dictionary URL from URL[#{url}]" if url.empty?()
50
50
 
data/lib/nhkore/news.rb CHANGED
@@ -49,7 +49,10 @@ module NHKore
49
49
  end
50
50
 
51
51
  def add_article(article,key: nil,overwrite: false)
52
- key = article.url if key.nil?()
52
+ url = article.url
53
+ url = url.to_s() unless url.nil?()
54
+
55
+ key = key.nil?() ? url : key.to_s()
53
56
 
54
57
  if !overwrite
55
58
  raise ArgumentError,"duplicate article[#{key}] in articles" if @articles.key?(key)
@@ -57,7 +60,7 @@ module NHKore
57
60
  end
58
61
 
59
62
  @articles[key] = article
60
- @sha256s[article.sha256] = article.url
63
+ @sha256s[article.sha256] = url
61
64
 
62
65
  return self
63
66
  end
@@ -91,16 +94,20 @@ module NHKore
91
94
  end
92
95
 
93
96
  def update_article(article,url)
97
+ url = url.to_s() unless url.nil?()
98
+
94
99
  # Favor https.
95
- return if article.url =~ FAVORED_URL
100
+ return if article.url.to_s() =~ FAVORED_URL
96
101
  return if url !~ FAVORED_URL
97
102
 
98
- @articles.delete(article.url)
103
+ @articles.delete(article.url) # Probably no to_s() here
99
104
  @articles[url] = article
100
105
  article.url = url
101
106
  end
102
107
 
103
108
  def article(key)
109
+ key = key.to_s() unless key.nil?()
110
+
104
111
  return @articles[key]
105
112
  end
106
113
 
@@ -119,6 +126,8 @@ module NHKore
119
126
  end
120
127
 
121
128
  def article?(key)
129
+ key = key.to_s() unless key.nil?()
130
+
122
131
  return @articles.key?(key)
123
132
  end
124
133
 
@@ -34,12 +34,12 @@ module NHKore
34
34
  # @since 0.2.0
35
35
  ###
36
36
  class SearchLink
37
- attr_accessor :datetime
38
- attr_accessor :futsuurl
37
+ attr_reader :datetime
38
+ attr_reader :futsuurl
39
39
  attr_accessor? :scraped
40
40
  attr_accessor :sha256
41
41
  attr_accessor :title
42
- attr_accessor :url
42
+ attr_reader :url
43
43
 
44
44
  def initialize(url,scraped: false)
45
45
  super()
@@ -49,29 +49,27 @@ module NHKore
49
49
  @scraped = scraped
50
50
  @sha256 = sha256
51
51
  @title = nil
52
- @url = url
52
+ self.url = url
53
53
  end
54
54
 
55
55
  def encode_with(coder)
56
56
  # Order matters.
57
57
 
58
- coder[:url] = @url
58
+ coder[:url] = @url.nil?() ? nil : @url.to_s()
59
59
  coder[:scraped] = @scraped
60
- coder[:datetime] = @datetime.nil?() ? @datetime : @datetime.iso8601()
60
+ coder[:datetime] = @datetime.nil?() ? nil : @datetime.iso8601()
61
61
  coder[:title] = @title
62
- coder[:futsuurl] = @futsuurl
62
+ coder[:futsuurl] = @futsuurl.nil?() ? nil : @futsuurl.to_s()
63
63
  coder[:sha256] = @sha256
64
64
  end
65
65
 
66
66
  def self.load_data(key,hash)
67
- datetime = hash[:datetime]
68
-
69
67
  slink = SearchLink.new(
70
68
  hash[:url],
71
- scraped: hash[:scraped]
69
+ scraped: hash[:scraped],
72
70
  )
73
71
 
74
- slink.datetime = Util.empty_web_str?(datetime) ? nil : Time.iso8601(datetime)
72
+ slink.datetime = hash[:datetime]
75
73
  slink.futsuurl = hash[:futsuurl]
76
74
  slink.sha256 = hash[:sha256]
77
75
  slink.title = hash[:title]
@@ -82,13 +80,31 @@ module NHKore
82
80
  def update_from_article(article)
83
81
  # Don't update the url, as it may be different (e.g., http vs https).
84
82
 
85
- @datetime = article.datetime if @datetime.nil?()
86
- @futsuurl = article.futsuurl if Util.empty_web_str?(@futsuurl)
83
+ self.datetime = article.datetime if @datetime.nil?()
84
+ self.futsuurl = article.futsuurl if Util.empty_web_str?(@futsuurl)
87
85
  @scraped = true # If we have an article, it's been scraped
88
86
  @sha256 = article.sha256 if Util.empty_web_str?(@sha256)
89
87
  @title = article.title if Util.empty_web_str?(@title)
90
88
  end
91
89
 
90
+ def datetime=(value)
91
+ if value.is_a?(Time)
92
+ @datetime = value
93
+ else
94
+ @datetime = Util.empty_web_str?(value) ? nil : Time.iso8601(value)
95
+ end
96
+ end
97
+
98
+ def futsuurl=(value)
99
+ # Don't store URI, store String.
100
+ @futsuurl = value.nil?() ? nil : value.to_s()
101
+ end
102
+
103
+ def url=(value)
104
+ # Don't store URI, store String.
105
+ @url = value.nil?() ? nil : value.to_s()
106
+ end
107
+
92
108
  def to_s(mini: false)
93
109
  s = ''.dup()
94
110
 
@@ -136,9 +152,11 @@ module NHKore
136
152
  end
137
153
 
138
154
  def add_link(link)
139
- return self if @links.key?(link.url)
155
+ url = link.url.nil?() ? nil : link.url.to_s()
156
+
157
+ return self if @links.key?(url)
140
158
 
141
- @links[link.url] = link
159
+ @links[url] = link
142
160
 
143
161
  return self
144
162
  end
@@ -162,7 +180,7 @@ module NHKore
162
180
 
163
181
  if !links.nil?()
164
182
  links.each() do |key,hash|
165
- key = key.to_s() # Change from a symbol
183
+ key = key.to_s() unless key.nil?()
166
184
  slinks.links[key] = SearchLink.load_data(key,hash)
167
185
  end
168
186
  end
@@ -172,6 +190,7 @@ module NHKore
172
190
 
173
191
  def [](url)
174
192
  url = url.url if url.respond_to?(:url)
193
+ url = url.to_s() unless url.nil?()
175
194
 
176
195
  return @links[url]
177
196
  end
@@ -22,5 +22,5 @@
22
22
 
23
23
 
24
24
  module NHKore
25
- VERSION = '0.3.4'
25
+ VERSION = '0.3.5'
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nhkore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bradley Whited (@esotericpig)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2020-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attr_bool
@@ -390,7 +390,7 @@ metadata:
390
390
  changelog_uri: https://github.com/esotericpig/nhkore/blob/master/CHANGELOG.md
391
391
  homepage_uri: https://github.com/esotericpig/nhkore
392
392
  source_code_uri: https://github.com/esotericpig/nhkore
393
- post_install_message: " \n NHKore v0.3.4\n \n You can now use [nhkore] on the
393
+ post_install_message: " \n NHKore v0.3.5\n \n You can now use [nhkore] on the
394
394
  command line.\n \n Homepage: https://github.com/esotericpig/nhkore\n \n Code:
395
395
  \ https://github.com/esotericpig/nhkore\n Changelog: https://github.com/esotericpig/nhkore/blob/master/CHANGELOG.md\n
396
396
  \ Bugs: https://github.com/esotericpig/nhkore/issues\n \n"