opml2org 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/opml2org +1 -1
- data/lib/opml.rb +2 -2
- data/lib/opml2org.rb +23 -25
- data/lib/opml2org/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01fcb46ec893386a485fddc98648131ec7d3c5db6396e2839aaab348c8aa7233
|
4
|
+
data.tar.gz: 833c68989e6d577cb894e9b97aeec097d6b18e13623386bb3a982618dd338cc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61f107f731817a54d462d10055e4ad94b09efe1faa5bcf287beccee120b50f4b41f53b09a9cf6c98bfbb83794331acb0dc4cdfda1a97d2a3d6fb64b549915550
|
7
|
+
data.tar.gz: ba8e346d3dbb412b43f130496a2f0ba7a283dafae9dcc9e545ed4cb1f04efd9ac2088c3f3689dbaf6f2612d1551bdbec60e52a13e891320f39736fb907899dda
|
data/exe/opml2org
CHANGED
data/lib/opml.rb
CHANGED
@@ -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
|
-
#
|
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
|
data/lib/opml2org.rb
CHANGED
@@ -1,39 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require 'opml2org/version'
|
2
2
|
require 'opml'
|
3
3
|
|
4
|
+
# converter from opml to org
|
4
5
|
class OpmlToOrg
|
5
|
-
def initialize(
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
[["\<", '<'],
|
15
|
+
["\>", '>'],
|
16
|
+
["\"", '"'],
|
17
|
+
["\'", "\'"],
|
18
|
+
["\&", "\&"]].each { |pair| text.gsub!(*pair) }
|
19
|
+
text
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
data/lib/opml2org/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|