bookmarks 0.1.1 → 0.2.0
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 +4 -4
- data/Changelog.markdown +6 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +3 -3
- data/README.markdown +2 -1
- data/VERSION +1 -1
- data/lib/bookmarks/document.rb +22 -1
- data/lib/bookmarks/netscape_bookmark.rb +36 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3245aeebe26e88b088bd079680022e2c07a12d85
|
4
|
+
data.tar.gz: a5bd9fd6a42e87f1dc9b7a491ff3f3aff0092480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8732c82641f01aeb904e5b663c486d6aaab591db2567f3361bcc2672456be031752db176c08efef73894b91d2066d3e19754afee7d6c573ffe74d8c86e5f1bc
|
7
|
+
data.tar.gz: a88867e39a47bc0d48a17999ec69ad862eca64ffcb396b80817ef25564a23215f7aec5cb51dfe9ffa5bb878fb78a67d853326f793a1ccbb540bfa68c584deb2c
|
data/Changelog.markdown
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bookmarks (0.
|
4
|
+
bookmarks (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -9,11 +9,11 @@ GEM
|
|
9
9
|
coco (0.7.1)
|
10
10
|
diff-lcs (1.2.4)
|
11
11
|
rake (10.1.0)
|
12
|
-
rspec (2.14.
|
12
|
+
rspec (2.14.1)
|
13
13
|
rspec-core (~> 2.14.0)
|
14
14
|
rspec-expectations (~> 2.14.0)
|
15
15
|
rspec-mocks (~> 2.14.0)
|
16
|
-
rspec-core (2.14.
|
16
|
+
rspec-core (2.14.4)
|
17
17
|
rspec-expectations (2.14.0)
|
18
18
|
diff-lcs (>= 1.1.3, < 2.0)
|
19
19
|
rspec-mocks (2.14.1)
|
data/README.markdown
CHANGED
@@ -5,7 +5,8 @@ Description
|
|
5
5
|
-----------
|
6
6
|
|
7
7
|
Bookmarks is a library to parse or build a file of bookmarks, currently
|
8
|
-
only files in netscape format, like the ones exported by Delicious
|
8
|
+
only files in netscape format, like the ones exported by Delicious or
|
9
|
+
Firefox.
|
9
10
|
|
10
11
|
Install
|
11
12
|
-------------------------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/bookmarks/document.rb
CHANGED
@@ -20,6 +20,7 @@ module Bookmarks
|
|
20
20
|
@document = ""
|
21
21
|
@bookmarks = []
|
22
22
|
@total = 0
|
23
|
+
@h3_tags = []
|
23
24
|
end
|
24
25
|
|
25
26
|
# Public: Returns the Symbol format of the document. Currently
|
@@ -75,14 +76,34 @@ module Bookmarks
|
|
75
76
|
# line - String.
|
76
77
|
#
|
77
78
|
# Returns nothing.
|
79
|
+
# TODO This should have its own parser class.
|
78
80
|
def parse_a_bookmark line
|
79
|
-
|
81
|
+
line = line.strip
|
82
|
+
if line =~ /^<DT><H3>/
|
83
|
+
@h3_tags << h3_tags(line)
|
84
|
+
elsif line =~ /^<\/DL>/
|
85
|
+
@h3_tags.pop
|
86
|
+
elsif line =~ /<DT><A/
|
80
87
|
@bookmarks << NetscapeBookmark.from_string(line)
|
88
|
+
if (not @h3_tags.empty?) && (not @bookmarks.last.nil?)
|
89
|
+
@bookmarks.last.add_tags @h3_tags
|
90
|
+
end
|
81
91
|
elsif line =~ /^<DD>/
|
82
92
|
@bookmarks.last.description = line[4..-1].chomp
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
96
|
+
# Get the h3's content of a line. H3 could be use as a tag in
|
97
|
+
# a netscape bookmark's file.
|
98
|
+
#
|
99
|
+
# line - String.
|
100
|
+
#
|
101
|
+
# Returns String h3 content or empty string.
|
102
|
+
def h3_tags line
|
103
|
+
md = /<H3>(.*?)<\/H3>/.match(line)
|
104
|
+
md ? md[1] : ""
|
105
|
+
end
|
106
|
+
|
86
107
|
|
87
108
|
# First part of a bookmark's file in netscape format.
|
88
109
|
FIRST_PART = <<CODE
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module Bookmarks
|
4
4
|
|
5
5
|
# Public: A single bookmark in netscape format.
|
6
|
+
#
|
7
|
+
# REVIEW Should we extract some of the class methods?
|
6
8
|
class NetscapeBookmark
|
7
9
|
|
8
10
|
# Public: Init a new NetscapeBookmark.
|
@@ -20,23 +22,18 @@ module Bookmarks
|
|
20
22
|
@description = description
|
21
23
|
end
|
22
24
|
|
23
|
-
# Public:
|
24
|
-
# a bookmarks file.
|
25
|
+
# Public: Add some tags to this bookmark.
|
25
26
|
#
|
26
|
-
#
|
27
|
+
# list - An Array of String tags.
|
27
28
|
#
|
28
|
-
# Returns
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
tags = /TAGS="(.*?)"/.match(line)[1]
|
35
|
-
title = prettify_title title, url
|
36
|
-
new url: url, title: title, date: date, tags: tags
|
29
|
+
# Returns nothing.
|
30
|
+
def add_tags list
|
31
|
+
unless @tags.empty?
|
32
|
+
@tags += ','
|
33
|
+
end
|
34
|
+
@tags += list.join(',')
|
37
35
|
end
|
38
36
|
|
39
|
-
|
40
37
|
# Public: Set/get the String url.
|
41
38
|
attr_accessor :url
|
42
39
|
|
@@ -65,6 +62,32 @@ module Bookmarks
|
|
65
62
|
end
|
66
63
|
end
|
67
64
|
|
65
|
+
# Public: Initialize a new NetscapeBookmark object from a line from
|
66
|
+
# a bookmarks file.
|
67
|
+
#
|
68
|
+
# line - String line from a bookmarks file.
|
69
|
+
#
|
70
|
+
# Returns a new NetscapeBookmark object.
|
71
|
+
def self.from_string line
|
72
|
+
url = /HREF="(.*?)"/.match(line)[1]
|
73
|
+
title = /HREF=.*>(.*)<\/A>$/.match(line)[1]
|
74
|
+
date = /ADD_DATE="(.*?)"/.match(line)[1]
|
75
|
+
date = Time.at(date.to_i).to_s
|
76
|
+
tags = self.extract_tags(line)
|
77
|
+
title = prettify_title title, url
|
78
|
+
new url: url, title: title, date: date, tags: tags
|
79
|
+
end
|
80
|
+
|
81
|
+
# Public: Get tags from a line from a bookmarks file.
|
82
|
+
#
|
83
|
+
# line - String line from a bookmarks file.
|
84
|
+
#
|
85
|
+
# Returns a String with tags or an empty string.
|
86
|
+
def self.extract_tags line
|
87
|
+
md = /TAGS="(.*?)"/.match(line)
|
88
|
+
md ? md[1] : ""
|
89
|
+
end
|
90
|
+
|
68
91
|
# In some case (which?) Delicious miss the title and we have a crapy
|
69
92
|
# 'None' instead of the original title. Bad news is the original title
|
70
93
|
# is lost. And there is no good news :) In such case, we build a new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookmarks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Nayrac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|