copilot 0.0.6 → 0.0.7

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.
@@ -0,0 +1,71 @@
1
+ require 'csv'
2
+
3
+ module CoPilot
4
+ class ArrayToCsvConverter
5
+
6
+ def initialize(array, options={})
7
+ @array = array
8
+ @include = options[:include]
9
+ @exclude = options[:exclude] || []
10
+ end
11
+
12
+ def convert
13
+ CSV.generate do |csv|
14
+ csv << columns
15
+ rows.each { |r| csv << columns.map { |c| format_value r[c] } }
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def rows
22
+ @rows ||= @array.map { |r| flatten r }
23
+ end
24
+
25
+ def columns
26
+ return @columns if @columns
27
+ columns = @include || extract_columns_from_rows
28
+ @columns = columns.reject { |c1| @exclude.index { |c2| c1 =~ c2 } }
29
+ end
30
+
31
+ def format_value(value)
32
+ value = remove_newlines value
33
+ remove_multiple_spaces value
34
+ end
35
+
36
+ def remove_newlines(value)
37
+ value.to_s.gsub "\n", ' '
38
+ end
39
+
40
+ def remove_multiple_spaces(value)
41
+ value.gsub(/ {2,}/, '')
42
+ end
43
+
44
+ def extract_columns_from_rows
45
+ keys = Set.new
46
+ rows.each { |r| keys += r.keys }
47
+ keys.sort
48
+ end
49
+
50
+ def flatten(enumerable)
51
+ res = {}
52
+
53
+ enumerable.each_with_index do |elem, i|
54
+ if elem.is_a?(Array)
55
+ k, v = elem
56
+ else
57
+ k, v = i, elem
58
+ end
59
+
60
+ if v.is_a? Enumerable
61
+ res.merge!(flatten k)
62
+ else
63
+ res[k] = v
64
+ end
65
+ end
66
+
67
+ res
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'array_to_csv_converter'
2
+
3
+ class Array
4
+
5
+ def to_csv(options={})
6
+ CoPilot::ArrayToCsvConverter.new(self, options).convert
7
+ end
8
+
9
+ end
data/lib/copilot.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'copilot/facade'
2
+ require_relative 'copilot/csv'
2
3
 
3
4
  module CoPilot
4
5
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copilot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-07 00:00:00.000000000 Z
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &70099948187940 !ruby/object:Gem::Requirement
16
+ requirement: &70328055296520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,13 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70099948187940
24
+ version_requirements: *70328055296520
25
25
  description:
26
26
  email: matthew-github@matthewriley.name
27
27
  executables: []
28
28
  extensions: []
29
29
  extra_rdoc_files: []
30
30
  files:
31
+ - lib/copilot/array_to_csv_converter.rb
32
+ - lib/copilot/csv.rb
31
33
  - lib/copilot/facade.rb
32
34
  - lib/copilot/requests/builds_for_bundle_id_request.rb
33
35
  - lib/copilot/requests/feedback_for_build_id_request.rb