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