openmeta.rb 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/lib/openmeta.rb +45 -2
- data/lib/openmeta/cli.rb +5 -35
- data/lib/openmeta/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 10a3d8f7c8578f7ac3e59eccf18cd104fef1baf1
|
4
|
-
data.tar.gz: 369d2b267e3fa6185b3971f547911be161e7b894
|
5
2
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce1f732416e536da204d4f3ad1900c101e0413abc2c236919ef69035a894ef3ee7d3bccb228fb1a7220cf21307ae3a1f34d2e55c0facd4d94c48fddcfe887d8d
|
4
|
+
data.tar.gz: bdc9d8a8cc54c29c0829f15215767a410540460e1da5b56e09391aa7b2ea9f6783d5f45e9d79993cc898250d9a83c499a1a87ee110e7b61a8e30cc7e256e844f
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: 4384cc488a0106eef40bf46391de0dace21dd1c1
|
7
|
+
data.tar.gz: 5d3fedc88d8e62b971a34580bfd7a12ce370f7e3
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
macruby
|
data/lib/openmeta.rb
CHANGED
@@ -75,9 +75,52 @@ module Openmeta
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
def clone(from_file, to_files)
|
79
|
+
unless File.exist?(from_file)
|
80
|
+
raise Openmeta::PathError, "#{from_file} does not exist!"
|
81
|
+
end
|
79
82
|
|
80
|
-
|
83
|
+
tags = get_tags(from_file)
|
84
|
+
rating = get_rating(from_file)
|
81
85
|
|
86
|
+
files.each { |file|
|
87
|
+
set_tags(tags, file) unless tags.empty?
|
88
|
+
set_rating(rating, file) unless rating == 0.0
|
89
|
+
}
|
90
|
+
end
|
82
91
|
|
92
|
+
def clear(files)
|
93
|
+
files.each { |file|
|
94
|
+
set_tags([], file)
|
95
|
+
set_rating(0.0, file)
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_tags(tags, to_files)
|
100
|
+
to_files.each { |file|
|
101
|
+
t = tags
|
102
|
+
existing_tags = get_tags(file)
|
103
|
+
# union
|
104
|
+
t |= existing_tags if existing_tags
|
105
|
+
|
106
|
+
unless t.eql? existing_tags
|
107
|
+
set_tags(t, file)
|
108
|
+
end
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def remove_tags(tags, to_files)
|
113
|
+
to_files.each { |file|
|
114
|
+
# duplicate a frozen array
|
115
|
+
existing_tags = get_tags(file).dup
|
116
|
+
unless existing_tags.empty?
|
117
|
+
existing_tags.delete_if { |t| tags.include?(t) }
|
118
|
+
set_tags(existing_tags, file)
|
119
|
+
end
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
83
126
|
|
data/lib/openmeta/cli.rb
CHANGED
@@ -31,18 +31,7 @@ module Openmeta
|
|
31
31
|
:type => :string,
|
32
32
|
:desc => "clone openmeta tags and rating from the FILE [required]"
|
33
33
|
def clone(*files)
|
34
|
-
|
35
|
-
unless File.exist?(from_file)
|
36
|
-
raise Openmeta::PathError, "#{from_file} does not exist!"
|
37
|
-
end
|
38
|
-
|
39
|
-
files.each { |file|
|
40
|
-
tags = Openmeta.get_tags(from_file)
|
41
|
-
rating = Openmeta.get_rating(from_file)
|
42
|
-
|
43
|
-
Openmeta.set_tags(tags, file) unless tags.empty?
|
44
|
-
Openmeta.set_rating(rating, file) unless rating == 0.0
|
45
|
-
}
|
34
|
+
Openmeta.clone(options[:from], files)
|
46
35
|
end
|
47
36
|
|
48
37
|
desc "get", "get openmeta tags and rating"
|
@@ -63,10 +52,7 @@ module Openmeta
|
|
63
52
|
|
64
53
|
desc "clear", "clear openmeta tags and rating"
|
65
54
|
def clear(*files)
|
66
|
-
files
|
67
|
-
Openmeta.set_tags([], file)
|
68
|
-
Openmeta.set_rating(0.0, file)
|
69
|
-
}
|
55
|
+
Openmeta.clear(files)
|
70
56
|
end
|
71
57
|
|
72
58
|
|
@@ -90,17 +76,8 @@ module Openmeta
|
|
90
76
|
:type => :string ,
|
91
77
|
:desc => "add tags, use ',' to separate multiple tags"
|
92
78
|
def add(*files)
|
93
|
-
|
94
|
-
|
95
|
-
tags = add_tags
|
96
|
-
existing_tags = Openmeta.get_tags(file)
|
97
|
-
# union
|
98
|
-
tags |= existing_tags if existing_tags
|
99
|
-
|
100
|
-
unless tags.eql? existing_tags
|
101
|
-
Openmeta.set_tags(tags, file)
|
102
|
-
end
|
103
|
-
}
|
79
|
+
tags = options[:tag].split(',')
|
80
|
+
Openmeta.add_tags(tags, files)
|
104
81
|
end
|
105
82
|
|
106
83
|
desc "remove", "remove openmeta tags, use ',' to separate multiple tags"
|
@@ -111,14 +88,7 @@ module Openmeta
|
|
111
88
|
:desc => "remove tags, use ',' to separate multiple tags"
|
112
89
|
def remove(*files)
|
113
90
|
tags = options[:tag].split(',')
|
114
|
-
|
115
|
-
# duplicate a frozen array
|
116
|
-
existing_tags = Openmeta.get_tags(file).dup
|
117
|
-
unless existing_tags.empty?
|
118
|
-
existing_tags.delete_if { |t| tags.include?(t) }
|
119
|
-
Openmeta.set_tags(existing_tags, file)
|
120
|
-
end
|
121
|
-
}
|
91
|
+
Openmeta.remove_tags(tags, files)
|
122
92
|
end
|
123
93
|
|
124
94
|
desc "rate", "set openmeta rating"
|
data/lib/openmeta/version.rb
CHANGED