enumark 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/README.md +12 -3
- data/lib/enumark.rb +47 -6
- data/lib/enumark/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: dd3e3db5143ec7096ee833bee0e94cd8fe7d1a058672b91410ce8f0cf9700beb
|
4
|
+
data.tar.gz: 5c2b9cce9297c14c6284e9962ceef8f1654cc7f38bcfb8abdeef80973d5aa6b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 842b05fadaa468ce5369d34fafd998897aa6aebb1a2059fae448058527ba3a839b7d8e527394777664df7e325e217618475550d43b9cdfc8f324db6fde14a9c3
|
7
|
+
data.tar.gz: ba52e4384a4a93fbf42dd4cc88ee8762e0935b99bef0681a857fb2b0e4855964f9c0deb17c42dc60bce9d82f7c364d55e8bb107057644f9c33803e81cca95a96
|
data/README.md
CHANGED
@@ -23,9 +23,18 @@ Or install it yourself as:
|
|
23
23
|
Create the enumerator with path to your dump file:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
Enumark.new('/path/to/bookmark_dump_file')
|
27
|
-
|
28
|
-
|
26
|
+
enum = Enumark.new('/path/to/bookmark_dump_file')
|
27
|
+
|
28
|
+
enum.each do |item|
|
29
|
+
item.name
|
30
|
+
item.href
|
31
|
+
item.host
|
32
|
+
item.categories
|
33
|
+
end
|
34
|
+
|
35
|
+
enum.each_host do |host|
|
36
|
+
host.name
|
37
|
+
host.items
|
29
38
|
end
|
30
39
|
```
|
31
40
|
|
data/lib/enumark.rb
CHANGED
@@ -26,11 +26,13 @@ class Enumark
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class Item
|
29
|
-
attr_reader :name, :categories
|
29
|
+
attr_reader :name, :href, :categories
|
30
|
+
|
31
|
+
USELESS_SHARP = /\#.*$/
|
30
32
|
|
31
33
|
def initialize(line, categories)
|
32
34
|
m = line.match(ITEM_NAME)
|
33
|
-
@href = m[1]
|
35
|
+
@href = m[1].gsub(USELESS_SHARP, '')
|
34
36
|
@add_date = m[2]
|
35
37
|
@name = m[3]
|
36
38
|
@categories = categories
|
@@ -43,6 +45,31 @@ class Enumark
|
|
43
45
|
def to_s
|
44
46
|
inspect
|
45
47
|
end
|
48
|
+
|
49
|
+
def host
|
50
|
+
@host ||= (URI.parse(href).host rescue 'unknown')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Hostname
|
55
|
+
attr_reader :name, :items
|
56
|
+
|
57
|
+
def initialize(name)
|
58
|
+
@name = name
|
59
|
+
@items = []
|
60
|
+
end
|
61
|
+
|
62
|
+
def add(item)
|
63
|
+
@items << item
|
64
|
+
end
|
65
|
+
|
66
|
+
def inspect
|
67
|
+
@name
|
68
|
+
end
|
69
|
+
|
70
|
+
def to
|
71
|
+
inspect
|
72
|
+
end
|
46
73
|
end
|
47
74
|
|
48
75
|
def initialize(file)
|
@@ -50,13 +77,27 @@ class Enumark
|
|
50
77
|
@lock = Mutex.new
|
51
78
|
@read = false
|
52
79
|
@items = []
|
53
|
-
end
|
54
80
|
|
55
|
-
|
56
|
-
|
81
|
+
@hosts_lock = Mutex.new
|
82
|
+
@hosts = nil
|
83
|
+
end
|
57
84
|
|
85
|
+
def each(&block)
|
58
86
|
read_all_lines
|
59
|
-
@items.each
|
87
|
+
@items.each(&block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def each_host(&block)
|
91
|
+
unless @hosts
|
92
|
+
@hosts_lock.synchronize do
|
93
|
+
next if @hosts
|
94
|
+
@hosts = each_with_object(Hash.new { |h, k| h[k] = Hostname.new(k) }) do |item, hash|
|
95
|
+
hash[item.host].add(item)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
@hosts.each_value(&block)
|
60
101
|
end
|
61
102
|
|
62
103
|
private
|
data/lib/enumark/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumark
|
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
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|