vitreous_share 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,6 +2,8 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'bundler'
4
4
 
5
+ include Rake::DSL
6
+
5
7
  Bundler::GemHelper.install_tasks
6
8
 
7
9
  task :default => :test
@@ -8,10 +8,10 @@ module Vitreous
8
8
  def generate( structure = [@structure] )
9
9
  Vitreous::Share::IndexerUtils.grouping( structure ).values.map do |e|
10
10
  {
11
- 'title' => Vitreous::Share::IndexerUtils.file_name_to_title( e[0]['name'] ),
11
+ 'title' => Vitreous::Share::IndexerUtils.to_title( e[0]['name'] ),
12
12
  'link' => Vitreous::Share::IndexerUtils.to_link( e[0]['path'] ),
13
13
  'type' => e.any? { |e2| e2['type'] == 'directory' } ? 'collection' : 'item',
14
- 'elements' => generate( e[0]['elements'] )
14
+ 'elements' => generate( e[0]['elements'].sort { |x, y| x['name'] <=> y['name'] } )
15
15
  }.merge( Vitreous::Share::IndexerUtils.meta( e ) )
16
16
  end
17
17
  end
@@ -21,4 +21,4 @@ module Vitreous
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -1,12 +1,16 @@
1
1
  module Vitreous
2
2
  module Share
3
3
  module IndexerUtils
4
- def self.file_name_to_title( file_name )
5
- remove_extensions( file_name ).gsub( /^\d*(_|\s)/, '' )
4
+ def self.to_title( string )
5
+ remove_digits( remove_extensions( string ) )
6
6
  end
7
7
 
8
- def self.remove_extensions( file_name )
9
- File.basename( file_name ).gsub( /\..*$/, '' )
8
+ def self.remove_digits( string )
9
+ string.gsub( /^\d*[_|\s]/, '' )
10
+ end
11
+
12
+ def self.remove_extensions( string )
13
+ File.basename( string ).gsub( /\..*$/, '' )
10
14
  end
11
15
 
12
16
  def self.to_link( path )
@@ -18,7 +22,7 @@ module Vitreous
18
22
  end
19
23
 
20
24
  def self.to_slug( string )
21
- string.
25
+ to_title( string ).
22
26
  downcase.
23
27
  gsub(/[^a-z0-9 -_]/,"").
24
28
  gsub('_', '-').
@@ -27,7 +31,7 @@ module Vitreous
27
31
 
28
32
  def self.grouping( elements )
29
33
  elements.group_by do |e|
30
- to_slug( remove_extensions( e['name'] ) )
34
+ to_slug( e['name'] )
31
35
  end
32
36
  end
33
37
 
@@ -1,5 +1,5 @@
1
1
  module Vitreous
2
2
  module Share
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/test/element_test.rb CHANGED
@@ -13,6 +13,6 @@ class ElementTest < Test::Unit::TestCase
13
13
  assert_equal( 1, element.items.size )
14
14
  assert_equal( 2, element.collections.size )
15
15
 
16
- assert_equal( '/file-1', element.elements.first.link )
16
+ assert_equal( '/subfolder-1', element.elements.first.link )
17
17
  end
18
18
  end
@@ -1,110 +1,110 @@
1
1
  {
2
2
  "title": "fixtures",
3
+ "link": "/",
4
+ "type": "collection",
3
5
  "elements": [
4
6
  {
5
- "jpg": "wadus uri",
6
- "title": "file 1",
7
- "txt": "file content",
8
- "txts": [
9
- "file content",
10
- "file content"
11
- ],
12
- "elements": [
13
-
14
- ],
15
- "type": "item",
16
- "link": "/file-1",
17
- "txt_thumb": "file content",
18
- "jpgs": [
19
- "wadus uri"
20
- ]
21
- },
22
- {
23
- "jpg": "wadus uri",
24
7
  "title": "subfolder 1",
25
- "txt": "file content",
26
- "txts": [
27
- "file content"
28
- ],
8
+ "link": "/subfolder-1",
9
+ "type": "collection",
29
10
  "elements": [
30
11
  {
31
- "jpg": "wadus uri",
32
- "title": "file 1",
33
- "txt": "file content",
34
- "txts": [
35
- "file content"
36
- ],
12
+ "title": "bbb",
13
+ "link": "/subfolder-1/bbb",
14
+ "type": "item",
37
15
  "elements": [
38
16
 
39
17
  ],
40
- "type": "item",
41
- "link": "/subfolder-1/file-1",
18
+ "jpg": "wadus uri",
19
+ "txt": "file content",
42
20
  "jpgs": [
43
21
  "wadus uri"
22
+ ],
23
+ "txts": [
24
+ "file content"
44
25
  ]
45
26
  },
46
27
  {
47
- "jpg": "wadus uri",
48
- "title": "file 2",
49
- "txt": "file content",
50
- "txts": [
51
- "file content"
52
- ],
28
+ "title": "aaa",
29
+ "link": "/subfolder-1/aaa",
30
+ "type": "item",
53
31
  "elements": [
54
32
 
55
33
  ],
56
- "type": "item",
57
- "link": "/subfolder-1/file-2",
34
+ "jpg": "wadus uri",
35
+ "txt": "file content",
58
36
  "jpgs": [
59
37
  "wadus uri"
38
+ ],
39
+ "txts": [
40
+ "file content"
60
41
  ]
61
42
  },
62
43
  {
63
44
  "title": "subsubfolder 1",
45
+ "link": "/subfolder-1/subsubfolder-1",
46
+ "type": "collection",
64
47
  "elements": [
65
48
  {
66
49
  "title": "file 1",
67
- "txt": "file content",
68
- "txts": [
69
- "file content"
70
- ],
50
+ "link": "/subfolder-1/subsubfolder-1/file-1",
51
+ "type": "item",
71
52
  "elements": [
72
53
 
73
54
  ],
74
- "type": "item",
75
- "link": "/subfolder-1/subsubfolder-1/file-1"
55
+ "txt": "file content",
56
+ "txts": [
57
+ "file content"
58
+ ]
76
59
  }
77
- ],
78
- "type": "collection",
79
- "link": "/subfolder-1/subsubfolder-1"
60
+ ]
80
61
  }
81
62
  ],
82
- "type": "collection",
83
- "link": "/subfolder-1",
63
+ "jpg": "wadus uri",
64
+ "txt": "file content",
84
65
  "jpgs": [
85
66
  "wadus uri"
67
+ ],
68
+ "txts": [
69
+ "file content"
86
70
  ]
87
71
  },
88
72
  {
89
73
  "title": "subfolder 2",
74
+ "link": "/subfolder-2",
75
+ "type": "collection",
90
76
  "elements": [
91
77
  {
92
78
  "title": "file 1",
93
- "txt": "file content",
94
- "txts": [
95
- "file content"
96
- ],
79
+ "link": "/subfolder-2/file-1",
80
+ "type": "item",
97
81
  "elements": [
98
82
 
99
83
  ],
100
- "type": "item",
101
- "link": "/subfolder-2/file-1"
84
+ "txt": "file content",
85
+ "txts": [
86
+ "file content"
87
+ ]
102
88
  }
89
+ ]
90
+ },
91
+ {
92
+ "title": "file 1",
93
+ "link": "/file-1",
94
+ "type": "item",
95
+ "elements": [
96
+
103
97
  ],
104
- "type": "collection",
105
- "link": "/subfolder-2"
98
+ "jpg": "wadus uri",
99
+ "txt_thumb": "file content",
100
+ "txt": "file content",
101
+ "jpgs": [
102
+ "wadus uri"
103
+ ],
104
+ "txts": [
105
+ "file content",
106
+ "file content"
107
+ ]
106
108
  }
107
- ],
108
- "type": "collection",
109
- "link": "/"
109
+ ]
110
110
  }
@@ -3,78 +3,48 @@
3
3
  "uri": "wadus uri",
4
4
  "elements": [
5
5
  {
6
- "name": "file 1.jpg",
7
- "uri": "wadus uri",
8
- "elements": [
9
-
10
- ],
11
- "type": "file",
12
- "content": null,
13
- "path": "/file 1.jpg"
14
- },
15
- {
16
- "name": "file 1.thumb.txt",
17
- "uri": "wadus uri",
18
- "elements": [
19
-
20
- ],
21
- "type": "file",
22
- "content": "file content",
23
- "path": "/file 1.thumb.txt"
24
- },
25
- {
26
- "name": "file 1.txt",
27
- "uri": "wadus uri",
28
- "elements": [
29
-
30
- ],
31
- "type": "file",
32
- "content": "file content",
33
- "path": "/file 1.txt"
34
- },
35
- {
36
- "name": "subfolder 1",
6
+ "name": "01 subfolder 1",
37
7
  "uri": "wadus uri",
38
8
  "elements": [
39
9
  {
40
- "name": "file 1.jpg",
10
+ "name": "001 bbb.jpg",
41
11
  "uri": "wadus uri",
42
12
  "elements": [
43
13
 
44
14
  ],
45
15
  "type": "file",
46
16
  "content": null,
47
- "path": "/subfolder 1/file 1.jpg"
17
+ "path": "/01 subfolder 1/001 bbb.jpg"
48
18
  },
49
19
  {
50
- "name": "file 1.txt",
20
+ "name": "001 bbb.txt",
51
21
  "uri": "wadus uri",
52
22
  "elements": [
53
23
 
54
24
  ],
55
25
  "type": "file",
56
26
  "content": "file content",
57
- "path": "/subfolder 1/file 1.txt"
27
+ "path": "/01 subfolder 1/001 bbb.txt"
58
28
  },
59
29
  {
60
- "name": "file 2.jpg",
30
+ "name": "002 aaa.jpg",
61
31
  "uri": "wadus uri",
62
32
  "elements": [
63
33
 
64
34
  ],
65
35
  "type": "file",
66
36
  "content": null,
67
- "path": "/subfolder 1/file 2.jpg"
37
+ "path": "/01 subfolder 1/002 aaa.jpg"
68
38
  },
69
39
  {
70
- "name": "file 2.txt",
40
+ "name": "002 aaa.txt",
71
41
  "uri": "wadus uri",
72
42
  "elements": [
73
43
 
74
44
  ],
75
45
  "type": "file",
76
46
  "content": "file content",
77
- "path": "/subfolder 1/file 2.txt"
47
+ "path": "/01 subfolder 1/002 aaa.txt"
78
48
  },
79
49
  {
80
50
  "name": "subsubfolder 1",
@@ -88,40 +58,40 @@
88
58
  ],
89
59
  "type": "file",
90
60
  "content": "file content",
91
- "path": "/subfolder 1/subsubfolder 1/file 1.txt"
61
+ "path": "/01 subfolder 1/subsubfolder 1/file 1.txt"
92
62
  }
93
63
  ],
94
64
  "type": "directory",
95
65
  "content": null,
96
- "path": "/subfolder 1/subsubfolder 1"
66
+ "path": "/01 subfolder 1/subsubfolder 1"
97
67
  }
98
68
  ],
99
69
  "type": "directory",
100
70
  "content": null,
101
- "path": "/subfolder 1"
71
+ "path": "/01 subfolder 1"
102
72
  },
103
73
  {
104
- "name": "subfolder 1.jpg",
74
+ "name": "01 subfolder 1.jpg",
105
75
  "uri": "wadus uri",
106
76
  "elements": [
107
77
 
108
78
  ],
109
79
  "type": "file",
110
80
  "content": null,
111
- "path": "/subfolder 1.jpg"
81
+ "path": "/01 subfolder 1.jpg"
112
82
  },
113
83
  {
114
- "name": "subfolder 1.txt",
84
+ "name": "01 subfolder 1.txt",
115
85
  "uri": "wadus uri",
116
86
  "elements": [
117
87
 
118
88
  ],
119
89
  "type": "file",
120
90
  "content": "file content",
121
- "path": "/subfolder 1.txt"
91
+ "path": "/01 subfolder 1.txt"
122
92
  },
123
93
  {
124
- "name": "subfolder 2",
94
+ "name": "02 subfolder 2",
125
95
  "uri": "wadus uri",
126
96
  "elements": [
127
97
  {
@@ -132,12 +102,42 @@
132
102
  ],
133
103
  "type": "file",
134
104
  "content": "file content",
135
- "path": "/subfolder 2/file 1.txt"
105
+ "path": "/02 subfolder 2/file 1.txt"
136
106
  }
137
107
  ],
138
108
  "type": "directory",
139
109
  "content": null,
140
- "path": "/subfolder 2"
110
+ "path": "/02 subfolder 2"
111
+ },
112
+ {
113
+ "name": "file 1.jpg",
114
+ "uri": "wadus uri",
115
+ "elements": [
116
+
117
+ ],
118
+ "type": "file",
119
+ "content": null,
120
+ "path": "/file 1.jpg"
121
+ },
122
+ {
123
+ "name": "file 1.thumb.txt",
124
+ "uri": "wadus uri",
125
+ "elements": [
126
+
127
+ ],
128
+ "type": "file",
129
+ "content": "file content",
130
+ "path": "/file 1.thumb.txt"
131
+ },
132
+ {
133
+ "name": "file 1.txt",
134
+ "uri": "wadus uri",
135
+ "elements": [
136
+
137
+ ],
138
+ "type": "file",
139
+ "content": "file content",
140
+ "path": "/file 1.txt"
141
141
  }
142
142
  ],
143
143
  "type": "directory",
@@ -1,25 +1,33 @@
1
+ # encoding: UTF-8
1
2
  require File.expand_path( "#{File.dirname(__FILE__)}/test_helper" )
2
3
 
3
4
  class IndexerUtilsTest < Test::Unit::TestCase
5
+
6
+ def test_to_title
7
+ assert_equal(
8
+ 'Pepe y Juán',
9
+ Vitreous::Share::IndexerUtils.to_title( '001 Pepe y Juán.txt' )
10
+ )
11
+ end
4
12
 
5
13
  def test_to_slug
6
14
  assert_equal(
7
15
  'pepe-y-jun',
8
- Vitreous::Share::IndexerUtils.to_slug( 'pepe y juán' )
16
+ Vitreous::Share::IndexerUtils.to_slug( '001 pepe y juán.txt' )
9
17
  )
10
18
  end
11
19
 
12
20
  def test_remove_extensions
13
21
  assert_equal(
14
- 'pepe y juán',
15
- Vitreous::Share::IndexerUtils.remove_extensions( 'pepe y juán.thumb.jpg' )
22
+ '001 pepe y juán',
23
+ Vitreous::Share::IndexerUtils.remove_extensions( '001 pepe y juán.thumb.jpg' )
16
24
  )
17
25
  end
18
26
 
19
27
  def test_to_link
20
28
  assert_equal(
21
29
  '/path-1/path-2/my-file',
22
- Vitreous::Share::IndexerUtils.to_link( '/Path 1/Path 2/My File.thumb.jpg' )
30
+ Vitreous::Share::IndexerUtils.to_link( '/01 Path 1/01 Path 2/01 My File.thumb.jpg' )
23
31
  )
24
32
 
25
33
  assert_equal(
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitreous_share
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 5
10
- version: 0.0.5
8
+ - 7
9
+ version: 0.0.7
11
10
  platform: ruby
12
11
  authors:
13
12
  - Fernando Guillen
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -68,7 +64,6 @@ dependencies:
68
64
  requirements:
69
65
  - - ">="
70
66
  - !ruby/object:Gem::Version
71
- hash: 15424057
72
67
  segments:
73
68
  - 1
74
69
  - 0
@@ -86,7 +81,6 @@ dependencies:
86
81
  requirements:
87
82
  - - ">="
88
83
  - !ruby/object:Gem::Version
89
- hash: 3
90
84
  segments:
91
85
  - 0
92
86
  version: "0"
@@ -100,7 +94,6 @@ dependencies:
100
94
  requirements:
101
95
  - - ">="
102
96
  - !ruby/object:Gem::Version
103
- hash: 3
104
97
  segments:
105
98
  - 0
106
99
  version: "0"
@@ -114,7 +107,6 @@ dependencies:
114
107
  requirements:
115
108
  - - ">="
116
109
  - !ruby/object:Gem::Version
117
- hash: 3
118
110
  segments:
119
111
  - 0
120
112
  version: "0"
@@ -148,17 +140,17 @@ files:
148
140
  - test/dropbox_structure_real_test.rb
149
141
  - test/dropbox_structure_test.rb
150
142
  - test/element_test.rb
143
+ - test/fixtures/folder_structure/01 subfolder 1.jpg
144
+ - test/fixtures/folder_structure/01 subfolder 1.txt
145
+ - test/fixtures/folder_structure/01 subfolder 1/001 bbb.jpg
146
+ - test/fixtures/folder_structure/01 subfolder 1/001 bbb.txt
147
+ - test/fixtures/folder_structure/01 subfolder 1/002 aaa.jpg
148
+ - test/fixtures/folder_structure/01 subfolder 1/002 aaa.txt
149
+ - test/fixtures/folder_structure/01 subfolder 1/subsubfolder 1/file 1.txt
150
+ - test/fixtures/folder_structure/02 subfolder 2/file 1.txt
151
151
  - test/fixtures/folder_structure/file 1.jpg
152
152
  - test/fixtures/folder_structure/file 1.thumb.txt
153
153
  - test/fixtures/folder_structure/file 1.txt
154
- - test/fixtures/folder_structure/subfolder 1.jpg
155
- - test/fixtures/folder_structure/subfolder 1.txt
156
- - test/fixtures/folder_structure/subfolder 1/file 1.jpg
157
- - test/fixtures/folder_structure/subfolder 1/file 1.txt
158
- - test/fixtures/folder_structure/subfolder 1/file 2.jpg
159
- - test/fixtures/folder_structure/subfolder 1/file 2.txt
160
- - test/fixtures/folder_structure/subfolder 1/subsubfolder 1/file 1.txt
161
- - test/fixtures/folder_structure/subfolder 2/file 1.txt
162
154
  - test/fixtures/index.json
163
155
  - test/fixtures/structure.json
164
156
  - test/index_searcher_test.rb
@@ -181,7 +173,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
173
  requirements:
182
174
  - - ">="
183
175
  - !ruby/object:Gem::Version
184
- hash: 3
185
176
  segments:
186
177
  - 0
187
178
  version: "0"
@@ -190,7 +181,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
181
  requirements:
191
182
  - - ">="
192
183
  - !ruby/object:Gem::Version
193
- hash: 3
194
184
  segments:
195
185
  - 0
196
186
  version: "0"
@@ -205,17 +195,17 @@ test_files:
205
195
  - test/dropbox_structure_real_test.rb
206
196
  - test/dropbox_structure_test.rb
207
197
  - test/element_test.rb
198
+ - test/fixtures/folder_structure/01 subfolder 1.jpg
199
+ - test/fixtures/folder_structure/01 subfolder 1.txt
200
+ - test/fixtures/folder_structure/01 subfolder 1/001 bbb.jpg
201
+ - test/fixtures/folder_structure/01 subfolder 1/001 bbb.txt
202
+ - test/fixtures/folder_structure/01 subfolder 1/002 aaa.jpg
203
+ - test/fixtures/folder_structure/01 subfolder 1/002 aaa.txt
204
+ - test/fixtures/folder_structure/01 subfolder 1/subsubfolder 1/file 1.txt
205
+ - test/fixtures/folder_structure/02 subfolder 2/file 1.txt
208
206
  - test/fixtures/folder_structure/file 1.jpg
209
207
  - test/fixtures/folder_structure/file 1.thumb.txt
210
208
  - test/fixtures/folder_structure/file 1.txt
211
- - test/fixtures/folder_structure/subfolder 1.jpg
212
- - test/fixtures/folder_structure/subfolder 1.txt
213
- - test/fixtures/folder_structure/subfolder 1/file 1.jpg
214
- - test/fixtures/folder_structure/subfolder 1/file 1.txt
215
- - test/fixtures/folder_structure/subfolder 1/file 2.jpg
216
- - test/fixtures/folder_structure/subfolder 1/file 2.txt
217
- - test/fixtures/folder_structure/subfolder 1/subsubfolder 1/file 1.txt
218
- - test/fixtures/folder_structure/subfolder 2/file 1.txt
219
209
  - test/fixtures/index.json
220
210
  - test/fixtures/structure.json
221
211
  - test/index_searcher_test.rb