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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 10a3d8f7c8578f7ac3e59eccf18cd104fef1baf1
4
- data.tar.gz: 369d2b267e3fa6185b3971f547911be161e7b894
5
2
  SHA512:
6
- metadata.gz: ecf6b15d8ffcc7003458583e4201cce9f467c41bd3a9f0e535c0c1c236f1bf7ac335ad2171e4a4f9c715129a17dedd5b689849599c4fcd6ccc7b55557b9dcd95
7
- data.tar.gz: 903cdbbe30a18a13cbc61df1c84701b53264d17c75908e3a505f6c0b9500eb24f29ee229a5095c7ca1699876a17cfee0a290dd7f7d162d6978e2162d637e8264
3
+ metadata.gz: ce1f732416e536da204d4f3ad1900c101e0413abc2c236919ef69035a894ef3ee7d3bccb228fb1a7220cf21307ae3a1f34d2e55c0facd4d94c48fddcfe887d8d
4
+ data.tar.gz: bdc9d8a8cc54c29c0829f15215767a410540460e1da5b56e09391aa7b2ea9f6783d5f45e9d79993cc898250d9a83c499a1a87ee110e7b61a8e30cc7e256e844f
5
+ SHA1:
6
+ metadata.gz: 4384cc488a0106eef40bf46391de0dace21dd1c1
7
+ data.tar.gz: 5d3fedc88d8e62b971a34580bfd7a12ce370f7e3
@@ -1 +1 @@
1
- system
1
+ macruby
@@ -75,9 +75,52 @@ module Openmeta
75
75
  end
76
76
  end
77
77
 
78
- end
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
- end
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
 
@@ -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
- from_file = options[:from]
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.each { |file|
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
- add_tags = options[:tag].split(',')
94
- files.each { |file|
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
- files.each { |file|
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"
@@ -1,4 +1,4 @@
1
1
  module Openmeta
2
- VERSION = '1.1.2'
2
+ VERSION = '1.2.0'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openmeta.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhao Cai