dir-to-xml 0.7.4 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fb015a4e5fa5d7de496e78649405a81c88c7fb6
4
- data.tar.gz: c9088c0c0f04ff6e2985d5e311d07fd491aa5b53
3
+ metadata.gz: 30753497dc3cb89192e2b16e2830a26ce5fef29c
4
+ data.tar.gz: fce05e271fa0d471391284a2218ca863e21135f5
5
5
  SHA512:
6
- metadata.gz: 4550171299f88f05832c7acceb6e3599c536248ac8e8aa3aa4df4309de10fe75271c64cc62c3055d66d31d4388103ab067dee7b2e7d1ed13f32272093d81f2d6
7
- data.tar.gz: 77747dcd0719ed898c7eacf72e8b942976f955cf387ccfec0b73efe20366a230b029990e7e0ee19e87fe264ac6f3ad9b28c7eaf2d619f71e507bb8adf96634ea
6
+ metadata.gz: 6790149b80e859dcd6486c79266a940be2d87eea37d076bf6008842d0a7e42ebe362f5a4bc3fcd45c9b92e858f9aac4915401190521fdf7f97469aab8e7e3d5d
7
+ data.tar.gz: 48f055d6452018949ddcc81ee853ea4bf9e2c233397f8d03ec2d69dd74c2bc4c6f57728f81d36d4303da4341e8c8ac2621183d339a2ff0df0677f66787dfd67f
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -7,7 +7,8 @@ require 'dynarex'
7
7
 
8
8
  class DirToXML
9
9
 
10
-
10
+ attr_reader :dx
11
+
11
12
  def initialize(path= '.', recursive: false, index: 'dir.xml')
12
13
 
13
14
  super()
@@ -35,20 +36,27 @@ class DirToXML
35
36
 
36
37
  end
37
38
 
38
- command = File.exists?(index) ? :refresh : :dxify
39
+ command = File.exists?(File.join(path, index)) ? :refresh : :dxify
39
40
 
40
41
  @dx = self.method(command).call a2
41
42
 
42
- @h = @dx.to_h
43
- @object = @h
43
+ @a = @dx.to_a
44
+ @object = @a
44
45
 
45
46
  end
46
47
 
47
- def filter(pattern=/.*/)
48
- @object = @h.select {|x| x[:name] =~ pattern }
48
+ def filter_by(pattern=/.*/, type: nil)
49
+
50
+ @object = @a.select do |x|
51
+
52
+ pattern_match = x[:name] =~ pattern
53
+ type_match = type ? x[:type] == type.to_s : true
54
+
55
+ end
56
+
49
57
  self
50
58
  end
51
-
59
+
52
60
  def find_by_filename(s)
53
61
  @dx.all.find {|item| item.name == s}
54
62
  end
@@ -58,7 +66,7 @@ class DirToXML
58
66
  def last_modified(ext=nil)
59
67
 
60
68
  if ext and ext != '*' then
61
- @object = @h.select{|x| x[:ext][/#{ext}/] or x[:type] == 'directory'}
69
+ @object = @a.select{|x| x[:ext][/#{ext}/] or x[:type] == 'directory'}
62
70
  end
63
71
 
64
72
  a = sort_by :mtime
@@ -78,7 +86,7 @@ class DirToXML
78
86
 
79
87
  def select_by_ext(ext)
80
88
 
81
- @object = ext != '*' ? @h.select{|x| x[:ext][/#{ext}/]} : @h
89
+ @object = ext != '*' ? @a.select{|x| x[:ext][/#{ext}/]} : @a
82
90
  self
83
91
  end
84
92
 
@@ -94,8 +102,12 @@ class DirToXML
94
102
 
95
103
  alias sort_by_lastmodified sort_by_last_modified
96
104
 
97
- def to_h
98
- @object || @h
105
+ def to_a
106
+ @object || @a
107
+ end
108
+
109
+ def to_h()
110
+ self.to_a.inject({}){|r,x| r.merge(x[:name] => x)}
99
111
  end
100
112
 
101
113
  def to_xml(options=nil)
@@ -120,19 +132,21 @@ class DirToXML
120
132
  dx.import a
121
133
 
122
134
  dx.save File.join(@path, @index)
123
-
135
+
124
136
  return dx
125
137
 
126
138
  end
127
139
 
128
140
  def refresh(cur_files)
129
141
 
130
- dx = Dynarex.new @index
142
+ dx = Dynarex.new File.join(@path, @index)
131
143
 
132
144
  prev_files = dx.to_a
133
145
 
134
146
  cur_files.each do |x|
147
+
135
148
  file = prev_files.find {|item| item[:name] == x[:name] }
149
+
136
150
  x[:description] = file[:description] if file and file[:description]
137
151
  end
138
152
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dir-to-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  iqgRYucyTfq3VLTy6wrGN2HJj8unXh4JIFjyEvR3yvcCYl6IaHxuDfgoDfBI6MeQ
32
32
  Em7HctRLQorltw==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-12-19 00:00:00.000000000 Z
34
+ date: 2015-12-25 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: dynarex
metadata.gz.sig CHANGED
Binary file