Module: OlympusCamera::CommandsParser
- Defined in:
- lib/olympus-camera/commands_parser.rb
Class Method Summary collapse
- .append_queries_walk_node(queries, nodes, n = 1) ⇒ Object
- .get_pair_queries(root) ⇒ Object
- .normalize_cgi_commands(cgi_commands) ⇒ Object
- .parse(xml) ⇒ Object
- .tail_array(array, r = []) ⇒ Object
Class Method Details
.append_queries_walk_node(queries, nodes, n = 1) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/olympus-camera/commands_parser.rb', line 62 def append_queries_walk_node(queries, nodes, n = 1) q = nodes.map do |node| commands = node["cmd#{n}"] commands_1 = node["cmd#{n + 1}"] name = node["name"] if commands if queries.length % 2 == 1 && !name queries = queries + [ANY] end appended = append_queries_walk_node(name ? queries + [name] : queries, commands, n) if commands_1 # for # <param1 name="startmovietake"> # <cmd2 name="limitter"/> # <cmd3 name="liveview"> # <param3 name="on"/> # </cmd3> # </param1 target = node.clone target.delete("cmd#{n}") target.delete("name") appended = (appended + append_queries_walk_node([], [target], n + 1)).flatten end appended elsif commands_1 appended = append_queries_walk_node([], commands_1, n) queries + [name, ANY] + appended.flatten else params = node["param#{n}"] if params && name append_queries_walk_node( queries + [name], params, n + 1 ) elsif name if queries.length % 2 == 0 queries + [name, ANY] else queries + [name] end elsif params else nil end end end.select { |a| a } tail_array(q) end |
.get_pair_queries(root) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/olympus-camera/commands_parser.rb', line 55 def get_pair_queries(root) qs = append_queries_walk_node([], [root]) qs.map { |q| Array.new((q.length / 2).floor).map { [q.shift, q.shift] } } end |
.normalize_cgi_commands(cgi_commands) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/olympus-camera/commands_parser.rb', line 20 def normalize_cgi_commands(cgi_commands) commands = {} cgi_commands.each do |data| name = data["name"].to_sym http_method = data["http_method"] && data["http_method"][0] if http_method method = http_method["type"].to_sym queries = get_pair_queries(http_method) commands[name] = { method: method, queries: queries, } else # e-m1-mark2.xml: cancel_trimresize commands[name] = { method: :get, queries: [], } end end commands end |
.parse(xml) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/olympus-camera/commands_parser.rb', line 8 def parse(xml) raw_commands = XmlSimple.xml_in xml api_version = raw_commands["version"][0] support_funcs = raw_commands["support"].map { |v| v["func"] } commands = normalize_cgi_commands raw_commands["cgi"] { api_version: api_version, support_funcs: support_funcs, commands: commands, } end |
.tail_array(array, r = []) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/olympus-camera/commands_parser.rb', line 44 def tail_array(array, r = []) array.each { |a| if a[0] && a[0].kind_of?(Array) tail_array a, r else r << a end } r end |