kcna 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66b4f906f215078226818809408690061af3561b
4
- data.tar.gz: 91857a54a93a46e71648983199f8ce5a49afee4f
3
+ metadata.gz: 5327663d6ee91c7c5b64b5d828b58b749e3f06c3
4
+ data.tar.gz: ada8b6736dbd21ffdf50e5a4a8f24678537cc425
5
5
  SHA512:
6
- metadata.gz: 587f36f1e416aa5374b0d607fecca5a8ffde3b79a9a7551cd1a45e48fe9760b809111bcd76a597342d046890bad02f318462ed193b19eca93342b4b7a9f8ad13
7
- data.tar.gz: f580279a254c66920f46cf0fd67d034598acf47a4a957979aa9c6d5654da2389b515c77e418163abf5824c3d19dded16ad12d449094465374bd4b91a71529437
6
+ metadata.gz: f76b20d8f7cd99b658db891f2c3b5621da41174fe0fa9d1b36fad71cdcdd05d0f1be7200e62b358efae3194fa6d8391af6a36b65154ef42db3d2f2c8c52040b1
7
+ data.tar.gz: ec393882b3eb2a5d75c88de3f3312caea26dc1e23acb4176db681d322e5bd6fd3671cce18d91a0fd030712f097d8c253b91298bec8fbd157fda9452068d2a7cb
data/README.md CHANGED
@@ -25,7 +25,7 @@ kcna.get_article_list.each do |article|
25
25
  end
26
26
  ```
27
27
 
28
- See also [RubyDoc](http://www.rubydoc.info/github/hinamiyagk/kcna.rb/master).
28
+ See also [RubyDoc](http://www.rubydoc.info/gems/kcna).
29
29
 
30
30
  ## License
31
31
 
@@ -32,14 +32,14 @@ class KCNA
32
32
  when "<br>"
33
33
  "\n"
34
34
  end
35
- end.sub(/(---|‐‐‐)$/, "")
35
+ end.sub(/\s*(---|‐‐‐|―――)\s*\z/, "")
36
36
  strip_html(replaced_content)
37
37
  end
38
38
 
39
39
  private def post(path, body, max_redirect = 3)
40
40
  raise "Too many redirects" if max_redirect == 0
41
41
 
42
- res = @client.post("http://kcna.kp#{path}", body: body)
42
+ res = @client.post("http://kcna.kp#{path}", body: body, header: { "Connection" => "Keep-Alive" })
43
43
  if res.ok?
44
44
  res
45
45
  elsif res.redirect?
@@ -3,7 +3,10 @@ class KCNA::Article
3
3
  # @return [String] ID of the article
4
4
  attr_reader :id
5
5
 
6
+ @attribute_keys = [:id]
7
+
6
8
  def self.attr_reader_hash(key, default = nil)
9
+ @attribute_keys.push(key)
7
10
  define_method(key, -> { @attrs[key].nil? ? default : @attrs[key] })
8
11
  end
9
12
  private_class_method :attr_reader_hash
@@ -19,7 +22,7 @@ class KCNA::Article
19
22
  attr_reader_hash :main_title
20
23
  # @!attribute [r]
21
24
  # @return [String] subtitle of the article
22
- attr_reader_hash :sub_title, ""
25
+ attr_reader_hash :sub_title
23
26
  # @!attribute [r]
24
27
  # @return [String]
25
28
  attr_reader_hash :display_title
@@ -47,4 +50,10 @@ class KCNA::Article
47
50
  @id = id
48
51
  @attrs = attrs
49
52
  end
53
+
54
+ # Convert the article to a hash table.
55
+ # @return [Hash]
56
+ def to_h
57
+ self.class.instance_variable_get(:@attribute_keys).map { |k| [k, self.send(k)] }.to_h
58
+ end
50
59
  end
@@ -1,3 +1,3 @@
1
1
  class KCNA
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kcna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hinata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-14 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  requirements: []
142
142
  rubyforge_project:
143
- rubygems_version: 2.6.12
143
+ rubygems_version: 2.6.13
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: A Ruby gem for kcna.kp(KCNA, Korean Central News Agency)