import_remotecontrol 0.1.7 → 0.1.8
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 +8 -8
- data/lib/import_code.rb +5 -1
- data/lib/import_remotecontrol.rb +0 -174
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmU4NTk1ODU3YzI4N2RjNTFhY2NiNjJhMGJjMjVjMTNlZDI4NDlmNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzU2Mzc1MThhMjhhMmM1NmNjNTczM2JlODdlY2NiNTEzM2NmYzA3MQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODQ1ZmVhMzc3N2QxYTg0MzU1M2I1Zjg3ZDc5ZjNlOTZjMGI0ODQ3Mjc3NDY4
|
10
|
+
NGMyOWY2NGU1MzEyN2E0N2UxYjAyMWIyYjIzM2MyNWUzZTcyNjZlMzE5ZWFj
|
11
|
+
Mjc5YWQ1M2EyZjZiM2VkZTM4NWM5MTRjY2ZlYjc2YjA1YmJlZDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDFmYTEwMTc1OWEzMTBhODY5NGM2OGE5MWI5NTY2ZWEzZTdkOTFjMDhkZTU5
|
14
|
+
OThkOWU0ODY1MTAyOWVhM2QzNGFmYzE2OTY1YzdlY2JmZGNkYjg0ZGEyMDVk
|
15
|
+
MWU5OTQyYmZkOGVjY2Y3YjA2MTdlZGRhOTAyNTVjNTBkMGQ0MzY=
|
data/lib/import_code.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#encoding:utf-8
|
2
|
+
require 'find'
|
2
3
|
module ImportCode
|
3
4
|
# To change this template use File | Settings | File Templates.
|
4
5
|
attr_accessor :file_path_array
|
@@ -135,9 +136,12 @@ module ImportCode
|
|
135
136
|
#protocol_user_code = codelist[1]
|
136
137
|
#other_code = ""
|
137
138
|
code = ""
|
139
|
+
p codelist
|
138
140
|
1.upto(codelist.size-1).each do |index|
|
139
|
-
code = codelist[index]
|
141
|
+
code =code + codelist[index]
|
142
|
+
code =code + ":" unless index == codelist.size-1
|
140
143
|
end
|
144
|
+
p code
|
141
145
|
{protocol_name:protocol,code:code}
|
142
146
|
end
|
143
147
|
|
data/lib/import_remotecontrol.rb
CHANGED
@@ -1,177 +1,3 @@
|
|
1
1
|
#encoding:utf-8
|
2
2
|
require 'find'
|
3
3
|
require 'import_code'
|
4
|
-
module ImportRemotecontrol
|
5
|
-
class ImportRemote
|
6
|
-
attr_accessor :file_path_array
|
7
|
-
attr_accessor :remote_code_array
|
8
|
-
attr_accessor :protocol_hash
|
9
|
-
|
10
|
-
DEFAULT_UNCLUDE = ["FileFormat","Remotecontroldescripe","Device","Brand","Model","Button'scounts"]
|
11
|
-
DEFAULT_NOIMPORT = ["FileFormat","Remotecontroldescripe","Button'scounts"]
|
12
|
-
|
13
|
-
METHOD_NAME = "method_name"
|
14
|
-
|
15
|
-
DEFAULT_CODENAME = {"机顶盒电源"=>"power","静音"=>"voice_quiet","菜单"=>"menu",
|
16
|
-
"上"=>"up","下"=>"down","左"=>"left","右"=>"right",
|
17
|
-
"音量+"=>'voice_up',"音量-"=>"voice_down",
|
18
|
-
"频道+"=>"channel_up","频道-"=>"channel_down"}
|
19
|
-
|
20
|
-
BRAND ="Brand"
|
21
|
-
MODEL = "model"
|
22
|
-
|
23
|
-
|
24
|
-
def self.get_error_msg(error,options={})
|
25
|
-
ret = ""
|
26
|
-
ret = ret + "ClassName: import_remotecontrol gem "
|
27
|
-
if options["method_name"]
|
28
|
-
ret = ret + "MethodName: #{options["method_name"]} "
|
29
|
-
end
|
30
|
-
if error
|
31
|
-
ret = ret + "Error Msg: #{error.to_s}"
|
32
|
-
end
|
33
|
-
ret
|
34
|
-
end
|
35
|
-
|
36
|
-
#遍历文件夹获取全部的文件名
|
37
|
-
def self.getFileNames(dir_path)
|
38
|
-
@file_path_array = []
|
39
|
-
begin
|
40
|
-
Find.find(dir_path).each do |path|
|
41
|
-
if FileTest.directory?(path)
|
42
|
-
Dir.foreach(path) do |file_path|
|
43
|
-
if(file_path != "."&&file_path!= "..")
|
44
|
-
if FileTest.directory?("#{path}/#{file_path}")
|
45
|
-
self.getFileNames("#{path}/#{file_path}")
|
46
|
-
else
|
47
|
-
if(file_path.eql?("protocol"))
|
48
|
-
getProtocolList("#{path}/#{file_path}")
|
49
|
-
else
|
50
|
-
@file_path_array << {"file_path"=>"#{path}/#{file_path}","file_name"=>"#{file_path}"}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
rescue => err
|
58
|
-
raise ArgumentError, get_error_msg(err,{METHOD_NAME => "getFileNames"})
|
59
|
-
end
|
60
|
-
@file_path_array
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
def self.isProcolCode?(key)
|
65
|
-
!DEFAULT_UNCLUDE.include?(key)
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.isBrand?(key)
|
69
|
-
key.eql?("Brand")
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
def self.getHashRemoteCode(file_path)
|
75
|
-
ret = {}
|
76
|
-
brand = ""
|
77
|
-
remote_code_line = File.read(file_path)
|
78
|
-
remote_code_line.split("\r\n").each do |code|
|
79
|
-
i = code.split("=")
|
80
|
-
if i.count>=2
|
81
|
-
i[0] = "" unless i[0]
|
82
|
-
key = i[0].gsub(" ","")
|
83
|
-
key = DEFAULT_CODENAME[key] if DEFAULT_CODENAME.has_key?(key)
|
84
|
-
if isBrand?(key)
|
85
|
-
brand = i[1]
|
86
|
-
end
|
87
|
-
if i
|
88
|
-
if i[0]
|
89
|
-
if(i[0].split(",").count > 1)
|
90
|
-
key = i[0].split(",")[1]
|
91
|
-
unless isProcolCode?(key)
|
92
|
-
ret.merge!({key => i[1]}) unless DEFAULT_NOIMPORT.include?(key)
|
93
|
-
else
|
94
|
-
codehash = disposeProtocolCode(i[1],brand)
|
95
|
-
ret.merge!({key=>codehash}) unless DEFAULT_NOIMPORT.include?(key)
|
96
|
-
end
|
97
|
-
else
|
98
|
-
ret.merge!({key=>i[1]}) unless DEFAULT_NOIMPORT.include?(key)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
ret
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.getProtocolList(file_path)
|
108
|
-
@protocol_hash = {}
|
109
|
-
protocol_lines = File.read(file_path)
|
110
|
-
protocol_lines.split("\n").each do |protocol_line|
|
111
|
-
protocol = protocol_line.split(":")
|
112
|
-
if(@protocol_hash.has_key?(protocol[0]))
|
113
|
-
@protocol_hash["#{protocol[0]}"].merge!({protocol[1]=>protocol[2]}) if protocol[2]!=nil&&protocol[2]!=""
|
114
|
-
else
|
115
|
-
@protocol_hash["#{protocol[0]}"] = {protocol[1]=>protocol[2]} if protocol[2]!=nil&&protocol[2]!=""
|
116
|
-
end
|
117
|
-
end
|
118
|
-
@protocol_hash
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
def self.disposeProtocolCode(codes,brand)
|
123
|
-
protocol = ""
|
124
|
-
codelist = codes.split(" ")
|
125
|
-
protocol_name = codelist[0]
|
126
|
-
if @protocol_hash[brand]
|
127
|
-
protocol = @protocol_hash[brand][protocol_name] if @protocol_hash[brand][protocol_name]
|
128
|
-
else
|
129
|
-
end
|
130
|
-
#protocol_user_code = codelist[1]
|
131
|
-
#other_code = ""
|
132
|
-
code = ""
|
133
|
-
1.upto(codelist.size-1).each do |index|
|
134
|
-
code = codelist[index] + ":"
|
135
|
-
end
|
136
|
-
{protocol_name:protocol,code:code}
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
def self.importRemoteCode(file_msg)
|
141
|
-
remote_code_hash = {}
|
142
|
-
begin
|
143
|
-
if file_msg
|
144
|
-
file_path = nil
|
145
|
-
file_path = file_msg["file_path"]
|
146
|
-
file_name = nil
|
147
|
-
file_name = file_msg["file_name"]
|
148
|
-
if file_path
|
149
|
-
remote_code_hash.merge!(getHashRemoteCode(file_path))
|
150
|
-
else
|
151
|
-
|
152
|
-
end
|
153
|
-
end
|
154
|
-
rescue => err
|
155
|
-
raise ArgumentError, get_error_msg(err,{METHOD_NAME => "importRemoteCode"})
|
156
|
-
end
|
157
|
-
remote_code_hash
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
def self.getRemoteCodeArray(dir_path)
|
165
|
-
@remote_code_array = []
|
166
|
-
if FileTest.directory?(dir_path)
|
167
|
-
filenames = getFileNames(dir_path)
|
168
|
-
filenames.each do |file_msg|
|
169
|
-
@remote_code_array<<importRemoteCode(file_msg)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
@remote_code_array
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
|
177
|
-
end
|