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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24e4772aa99824cfda1c6c84ea6ff8affffdbcde48f2c8da12eae51a3a4f4bf5
4
- data.tar.gz: e0073bb2df270c7182d9e2b359e2edfd947d58bb9ea6bc17b1690294e4c05dec
3
+ metadata.gz: dd3e3db5143ec7096ee833bee0e94cd8fe7d1a058672b91410ce8f0cf9700beb
4
+ data.tar.gz: 5c2b9cce9297c14c6284e9962ceef8f1654cc7f38bcfb8abdeef80973d5aa6b1
5
5
  SHA512:
6
- metadata.gz: d6cd93ba202034d3bf7741813a11541340c0661e6112e1473b6c5b02d7ca34703fbb25d2841cfe0fa003ef62c0c0b28356eded892e3cc42091db719853c4e15c
7
- data.tar.gz: 82613b50ba4abc34caf9268733e8e885d8b53239858c93949e617e08e08dc3807a7f4cc088d24f422d11ae18b3f35e8b816b48adac9088dbde23b5af02b47bf5
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').each do |e|
27
- e.name
28
- e.categories
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
- def each
56
- return self unless block_given?
81
+ @hosts_lock = Mutex.new
82
+ @hosts = nil
83
+ end
57
84
 
85
+ def each(&block)
58
86
  read_all_lines
59
- @items.each { |item| yield item }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Enumark
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
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 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry