enumark 0.1.1 → 0.1.2

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: dd3e3db5143ec7096ee833bee0e94cd8fe7d1a058672b91410ce8f0cf9700beb
4
- data.tar.gz: 5c2b9cce9297c14c6284e9962ceef8f1654cc7f38bcfb8abdeef80973d5aa6b1
3
+ metadata.gz: 5ff7445e38a40b2f5e2e7196c9873833d1853c8994cf0ac13699c322174658ee
4
+ data.tar.gz: 2d679d07bed90e0973701f6fd01a5a6b2c0c86bf61529a97d3ade1d57d68ca4c
5
5
  SHA512:
6
- metadata.gz: 842b05fadaa468ce5369d34fafd998897aa6aebb1a2059fae448058527ba3a839b7d8e527394777664df7e325e217618475550d43b9cdfc8f324db6fde14a9c3
7
- data.tar.gz: ba52e4384a4a93fbf42dd4cc88ee8762e0935b99bef0681a857fb2b0e4855964f9c0deb17c42dc60bce9d82f7c364d55e8bb107057644f9c33803e81cca95a96
6
+ metadata.gz: 6ab4b15cf7de8e56c3af1e681f369258e9806b34736e2ffb5df85c4195a9be354c272d46e2627c5f1bf8bd69b26f9144ac1f46736835926f481c2a5bc0204a92
7
+ data.tar.gz: c86177d92d36168653a669d5f11ed2136549026760c042a89ad385aece50bcc1faf69e269c30fcf2ae57d53b9df839db200fe3a0a7cd5f335b28463fdfc2a255
data/README.md CHANGED
@@ -36,6 +36,16 @@ enum.each_host do |host|
36
36
  host.name
37
37
  host.items
38
38
  end
39
+
40
+ enum.each_dup_title do |title|
41
+ title.name
42
+ title.items
43
+ end
44
+
45
+ enum.each_dup_href do |href|
46
+ href.name
47
+ href.items
48
+ end
39
49
  ```
40
50
 
41
51
  ## Development
data/lib/enumark.rb CHANGED
@@ -72,14 +72,40 @@ class Enumark
72
72
  end
73
73
  end
74
74
 
75
+ class Grouping
76
+ Group = Struct.new(:name, :items)
77
+
78
+ def initialize(enumark, key, &post)
79
+ @lock = Mutex.new
80
+ @collection = nil
81
+
82
+ @enumark = enumark
83
+ @key = key
84
+ @post = post
85
+ end
86
+
87
+ def each(&block)
88
+ unless @collection
89
+ @lock.synchronize do
90
+ @collection = @enumark.group_by(&@key)
91
+ @collection = @post.call(@collection) if @post
92
+ @collection = @collection.map{ |k, items| Group.new(k, items) }
93
+ end
94
+ end
95
+
96
+ @collection.each(&block)
97
+ end
98
+ end
99
+
75
100
  def initialize(file)
76
101
  @file = file
77
102
  @lock = Mutex.new
78
103
  @read = false
79
104
  @items = []
80
105
 
81
- @hosts_lock = Mutex.new
82
- @hosts = nil
106
+ @hosts = Grouping.new(self, :host)
107
+ @dup_titles = Grouping.new(self, :name){ |groups| groups.select{ |_, items| items.count > 1 } }
108
+ @dup_hrefs = Grouping.new(self, :href){ |groups| groups.select{ |_, items| items.count > 1 } }
83
109
  end
84
110
 
85
111
  def each(&block)
@@ -88,16 +114,15 @@ class Enumark
88
114
  end
89
115
 
90
116
  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
117
+ @hosts.each(&block)
118
+ end
119
+
120
+ def each_dup_title(&block)
121
+ @dup_titles.each(&block)
122
+ end
99
123
 
100
- @hosts.each_value(&block)
124
+ def each_dup_href(&block)
125
+ @dup_hrefs.each(&block)
101
126
  end
102
127
 
103
128
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Enumark
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-12 00:00:00.000000000 Z
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry