import_remotecontrol 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/import_remotecontrol.rb +111 -15
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDVmNDAzOTU1ZTMwMDI1MWNiYzZkODE3MGRhNThjMTk0NmVhZGVhNg==
4
+ OGQyODlmYzliNWY2N2ExNmRhNWM2M2IzZTliNzU0NzJjMzUyNWI1NA==
5
5
  data.tar.gz: !binary |-
6
- MDY0ZjBhMGIyZDk0Njc2ZWMzZDY5MzJhYmJjZTlhYTRlMmJlNTdhYQ==
6
+ ZGEwNTRhNWFmNTBjZGZiZWE5MGVlZjJmMDg1MDhlZDM5MGJiOTk0Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTQzNTg5ODQ3ZGM1ZTQ3MTljMGU3YTA2YTNiNTBmZjQ2OTBlMDc2ZmU4Mjll
10
- ZDAzMmJjOGRkYTcwNmNjM2Y4OTE5YzhkMDYzNmEyYTg3OTRhYmY1MjUwY2Nk
11
- ZDJiYTdlZDIyODBkOGQxN2Q4YjE1ODhjMWNhMDdkNGVjZjcyMDA=
9
+ NWUwOTZhYTZhNTI0YWQ0ODZiYTUwZTM5MDBhYjdkMjY4NjRjNWRiZTY0YzI5
10
+ MDljODY4MTljYjIyMWMwNTJkYjBiNzVhZDA3YzlmY2IwOTVhZjNmOTc5Yjk2
11
+ ZGE4YjQ3YTVkZmEwZTkwOWM2OTVhNzJjZjIxZWQxN2QzYzk4MmU=
12
12
  data.tar.gz: !binary |-
13
- MzMwZGMzOWQ1Nzk4ZDNjMzgwYWY0MThiMmQzNzJlNjM2ZmJiNzU2NjRmYTQ0
14
- Y2U5MDcxZTZmY2M3NjJiNTRiN2Q4YWViYWZlZDlkMTZlOTYzMjI5NjVkMjhh
15
- MzVhNzE5ZjJmZjgxNDhhMTY0ZjQ5YzlkMjkyMDc1ZDU1YjQwODY=
13
+ NDYzNzcxNzkxNjc5MzcyNjZlY2M1OTMzNjljYTQ3MzA5OTgxMTAwYmVkOGU1
14
+ NTRmZDIyNjU4NWJjZTY3Y2ZhY2U3NWY5NTU2MTY0OWFkNjNlM2E2ZWIxY2E0
15
+ YWMxNjlhZjUyZmZkNjUyYmE1YmY1ODg4NjViZThiZjU5NzVjYzA=
@@ -4,58 +4,154 @@ module ImportRemotecontrol
4
4
  class ImportRemote
5
5
  attr_accessor :file_path_array
6
6
  attr_accessor :remote_code_array
7
+ attr_accessor :protocol_hash
8
+
9
+ DEFAULT_UNCLUDE = ["FileFormat","Remote control descripe","Device","Brand","Model","Button's counts"]
10
+
11
+ METHOD_NAME = "method_name"
12
+
13
+ def self.get_error_msg(error,options={})
14
+ ret = ""
15
+ ret = ret + "ClassName: import_remotecontrol gem "
16
+ if options["method_name"]
17
+ ret = ret + "MethodName: #{options["method_name"]} "
18
+ end
19
+ if error
20
+ ret = ret + "Error Msg: #{error.to_s}"
21
+ end
22
+ ret
23
+ end
7
24
 
8
25
  #遍历文件夹获取全部的文件名
9
26
  def self.getFileNames(dir_path)
10
27
  @file_path_array = []
28
+ begin
11
29
  Find.find(dir_path).each do |path|
12
30
  if FileTest.directory?(path)
13
- p path
14
31
  Dir.foreach(path) do |file_path|
15
32
  if(file_path != "."&&file_path!= "..")
16
33
  if FileTest.directory?("#{path}/#{file_path}")
17
- p file_path
18
34
  self.getFileNames("#{path}/#{file_path}")
19
35
  else
20
- p "Where Put #{file_path}"
21
- @file_path_array << "#{path}/#{file_path}"
36
+ if(file_path.eql?("protocol"))
37
+ getProtocolList("#{path}/#{file_path}")
38
+ else
39
+ @file_path_array << {"file_path"=>"#{path}/#{file_path}","file_name"=>"#{file_path}"}
40
+ end
22
41
  end
23
42
  end
24
43
  end
25
44
  end
26
45
  end
46
+ rescue => err
47
+ raise ArgumentError, get_error_msg(err,{METHOD_NAME => "getFileNames"})
48
+ end
27
49
  @file_path_array
28
50
  end
29
51
 
30
52
 
53
+ def self.isProcolCode?(key)
54
+ !DEFAULT_UNCLUDE.include?(key)
55
+ end
56
+
57
+ def self.isBrand?(key)
58
+ key.eql?("Brand")
59
+ end
60
+
61
+
31
62
 
32
63
  def self.getHashRemoteCode(file_path)
33
- p "In get HashRemoteCode"
34
- remote_code_hash = {}
64
+ ret = {}
65
+ brand = ""
35
66
  remote_code_line = File.read(file_path)
36
67
  remote_code_line.split("\r\n").each do |code|
37
68
  i = code.split("=")
38
- key = i[0]
39
- if i
40
- if i[0]
41
- if(i[0].split(",").count > 1)
42
- key = i[0].split(",")[1]
69
+ if i.count>=2
70
+ i[0] = "" unless i[0]
71
+ key = i[0].gsub(" ","")
72
+ if isBrand?(key)
73
+ brand = i[1]
74
+ end
75
+ if i
76
+ if i[0]
77
+ if(i[0].split(",").count > 1)
78
+ key = i[0].split(",")[1]
79
+ unless isProcolCode?(key)
80
+ ret={key => i[1]}
81
+ else
82
+ codehash = disposeProtocolCode(i[1],brand)
83
+ ret={key=>codehash}
84
+ end
85
+ end
43
86
  end
44
87
  end
45
88
  end
46
- remote_code_hash.merge!({key => i[1]})
89
+ end
90
+ ret
91
+ end
92
+
93
+ def self.getProtocolList(file_path)
94
+ @protocol_hash = {}
95
+ protocol_lines = File.read(file_path)
96
+ protocol_lines.split("\n").each do |protocol_line|
97
+ protocol = protocol_line.split(":")
98
+ if(@protocol_hash.has_key?(protocol[0]))
99
+ @protocol_hash["#{protocol[0]}"].merge!({protocol[1]=>protocol[2]}) if protocol[2]!=nil&&protocol[2]!=""
100
+ else
101
+ @protocol_hash["#{protocol[0]}"] = {protocol[1]=>protocol[2]} if protocol[2]!=nil&&protocol[2]!=""
102
+ end
103
+ end
104
+ @protocol_hash
105
+ end
106
+
107
+
108
+ def self.disposeProtocolCode(codes,brand)
109
+ protocol = ""
110
+ codelist = codes.split(" ")
111
+ protocol_name = codelist[0]
112
+ if @protocol_hash[brand]
113
+ protocol = @protocol_hash[brand][protocol_name] if @protocol_hash[brand][protocol_name]
114
+ else
115
+ end
116
+ protocol_user_code = codelist[1]
117
+ other_code = ""
118
+ 2.upto(codelist.size-1).each do |index|
119
+ other_code = codelist[index] + ":"
120
+ end
121
+ {protocol_name:protocol,user_code:protocol_user_code,other_code:other_code}
122
+ end
123
+
124
+
125
+ def self.importRemoteCode(file_msg)
126
+ remote_code_hash = {}
127
+ begin
128
+ if file_msg
129
+ file_path = nil
130
+ file_path = file_msg["file_path"]
131
+ file_name = nil
132
+ file_name = file_msg["file_name"]
133
+ if file_path
134
+ remote_code_hash.merge!(getHashRemoteCode(file_path))
135
+ else
136
+
137
+ end
138
+ end
139
+ rescue => err
140
+ raise ArgumentError, get_error_msg(err,{METHOD_NAME => "importRemoteCode"})
47
141
  end
48
142
  remote_code_hash
49
143
  end
50
144
 
51
145
 
146
+
147
+
148
+
52
149
  def self.getRemoteCodeArray(dir_path)
53
150
  @remote_code_array = []
54
151
  if FileTest.directory?(dir_path)
55
152
  filenames = getFileNames(dir_path)
56
- filenames.each do |file_path|
57
- p file_path
58
- @remote_code_array << getHashRemoteCode(file_path)
153
+ filenames.each do |file_msg|
154
+ @remote_code_array<<importRemoteCode(file_msg)
59
155
  end
60
156
  end
61
157
  @remote_code_array
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: import_remotecontrol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - zql
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-16 00:00:00.000000000 Z
11
+ date: 2013-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: only use import remote control code
14
14
  email: hahazhouqunli@gmail.com