opml2org 0.1.0 → 0.1.1

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: b52704c6301d351d01ecc9f06e20841fb576e75bf34694ae56e58f23ea85d3af
4
- data.tar.gz: 37c88f703f2c44fd0a438b315ebc907c1d0951cd3aac2210617f17b343b64519
3
+ metadata.gz: 01fcb46ec893386a485fddc98648131ec7d3c5db6396e2839aaab348c8aa7233
4
+ data.tar.gz: 833c68989e6d577cb894e9b97aeec097d6b18e13623386bb3a982618dd338cc3
5
5
  SHA512:
6
- metadata.gz: 379d4496b6e56c9932da9a358fd3c9c38377af495b5915f3c803612769c33bccb01e41cc0e4b75cbc55f7ab1a65224c4e8ffcbfa25ab6f715d46e2d2ebbf99a1
7
- data.tar.gz: 4c053ac0714181cf1a39568759366fba861673ed4dc8f9c6a42504f6a13746059c31a530052c022e562fd822cdffad200b194f3d6a3bb5d37c05f2e3ae9e351d
6
+ metadata.gz: 61f107f731817a54d462d10055e4ad94b09efe1faa5bcf287beccee120b50f4b41f53b09a9cf6c98bfbb83794331acb0dc4cdfda1a97d2a3d6fb64b549915550
7
+ data.tar.gz: ba8e346d3dbb412b43f130496a2f0ba7a283dafae9dcc9e545ed4cb1f04efd9ac2088c3f3689dbaf6f2612d1551bdbec60e52a13e891320f39736fb907899dda
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "opml2org"
4
4
 
5
- OpmlToOrg.new(ARGV)
5
+ OpmlToOrg.new(ARGV[0])
@@ -39,10 +39,10 @@ class Opml
39
39
 
40
40
  private
41
41
  def map_attributes_to_hash(attributes)
42
+ hash = {}
42
43
  # returning({}) do |hash|
43
44
  # attributes.each { |key, value| hash[key.underscore] = value }
44
45
  # end
45
- hash = {}
46
46
  attributes.each{ |key, value| hash[key] = value }
47
47
  return hash
48
48
  end
@@ -77,7 +77,7 @@ class Opml
77
77
  end
78
78
 
79
79
  def get_head_value(attribute)
80
- # if element = @doc.elements["opml/head/#{attribute.to_s.camelize(:lower)}"]
80
+ # if element = @doc.elements["opml/head/#{attribute.to_s.camelize(:lower)}"]
81
81
  if element = @doc.elements["opml/head/#{attribute.to_s}"]
82
82
  element.text
83
83
  end
@@ -1,39 +1,37 @@
1
- require "opml2org/version"
1
+ require 'opml2org/version'
2
2
  require 'opml'
3
3
 
4
+ # converter from opml to org
4
5
  class OpmlToOrg
5
- def initialize(*argv)
6
- file = argv.flatten[0]
6
+ def initialize(file)
7
7
  docs = Opml.new(File.read(file))
8
8
  print recursive_output(docs, 1)
9
9
  end
10
10
 
11
11
  private
12
+
12
13
  def plain_text(text)
13
- text.gsub!("\&lt;",'<')
14
- text.gsub!("\&gt;",'>')
15
- text.gsub!("\&quot;",'"')
16
- text.gsub!("\&apos;","\'")
17
- text.gsub!("\&amp;","\&")
18
- return text
14
+ [["\&lt;", '<'],
15
+ ["\&gt;", '>'],
16
+ ["\&quot;", '"'],
17
+ ["\&apos;", "\'"],
18
+ ["\&amp;", "\&"]].each { |pair| text.gsub!(*pair) }
19
+ text
19
20
  end
20
21
 
21
- def recursive_output(second, level)
22
- text = ''
23
- if second.outlines.size>0
24
- second.outlines.each do |third|
25
- if third.attributes['text']
26
- p_t = plain_text(third.attributes['text'])
27
- if level > 2
28
- text << '-'*(level-2)+" #{p_t}\n"
29
- else
30
- text << '*'*level+" #{p_t}\n"
31
- end
32
- text << recursive_output(third, level+1)
33
- end
34
- end
35
- end
36
- return text
22
+ LEVEL = 2
23
+ def to_org(text, level)
24
+ mark = level > LEVEL ? '-' * (level - LEVEL) : '*' * level
25
+ mark + plain_text(text) + "\n"
37
26
  end
38
27
 
28
+ def recursive_output(curr, level)
29
+ return '' if curr.outlines.empty?
30
+ curr.outlines.inject('') do |result, ele|
31
+ text = ele.attributes['text']
32
+ next ele unless text
33
+ result << to_org(text, level)
34
+ result << recursive_output(ele, level + 1)
35
+ end
36
+ end
39
37
  end
@@ -1,3 +1,3 @@
1
1
  module Opml2org
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opml2org
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shigeto R. Nishitani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler