letter_group 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3af31eadc667a91267e1dc0553c72df294c87e41
4
- data.tar.gz: ec1270a8c43a3a37716d036b8037f2a8ab3617ff
3
+ metadata.gz: 5c423bf8418a73de8f19c6f4c4dd5136aee163cd
4
+ data.tar.gz: 0cd2888b3b53b32948c7a8afc88736fb1b523dcf
5
5
  SHA512:
6
- metadata.gz: 05f0ff0547e3b71fa1b584cf717d729d5aac3943db59a2f079b2e41c524dd96afb1c895aadcd826e9c4e037d7bd50489712795b233985c5346ccaead62733919
7
- data.tar.gz: 1601feb1f22e896cad9773a1cd9a0d480e2e3a9da9a5093b37887d5d87fd4e256792d13e69a1e5453e435e95ad20aab910a812d710238f0854f7ebb8ec097325
6
+ metadata.gz: d88f0bc531704821358b98ed7e9407c030e7b4df6559988abbab43aeb0a40f5787f9d74c85e239c5a00f3ea6edf5adf7e88ab63f1123dadca513c1a61f1c9354
7
+ data.tar.gz: 603666bfd39d7aacdf391a7c658019f8a824e35b4eb67f7d81bc34ed9827cde75c341fe02a1457b7b0b7fb34d57c6f7c8fb9b0f790a969511d13711a42198b88
@@ -29,17 +29,19 @@
29
29
  # "name" => ["leads_first_name", "ol_first_name"]
30
30
  # }
31
31
  # default {}
32
+ # param labels - optional, false for no labels, true to use column names from first field group, or an array to provide custom labels.
32
33
 
33
34
  module LetterGroup
34
35
  class Group
35
36
 
36
37
  attr_reader :rows, :letter, :total, :unique_key, :fields, :field_groups, :labels
37
38
 
38
- def initialize(array_of_hashes = [], letter: "", unique_key: nil, fields: [], field_groups: {})
39
+ def initialize(array_of_hashes = [], letter: "", unique_key: nil, fields: [], field_groups: {}, labels: true)
39
40
  @array_of_hashes = array_of_hashes || []
40
41
  @letter = (letter || "").upcase
41
42
  # when unique_key is nil results in a single Tuple with a set for all the rows in this group.
42
43
  @unique_key = unique_key
44
+ @labels = labels
43
45
  determine_fields(fields, field_groups)
44
46
  fill_rows
45
47
  end
@@ -70,14 +72,17 @@ module LetterGroup
70
72
  @field_groups = @fields.inject({}) {|memo, elem| memo[elem] = Array(elem); memo}
71
73
  end
72
74
  @num_fields = @fields.length
73
- # The column names in the first field_group will be used as labels in the view.
74
- # so for { "ID" => ["lead_id", "user_id"] }
75
- # the labels are the array ["lead_id","user_id"]
76
- @labels = if @field_groups.first
77
- @field_groups.first[1]
78
- else
79
- []
80
- end
75
+ # If @labels are desired, but haven't been provided by caller, set a default.
76
+ if @labels && !@labels.is_a?(Array)
77
+ # The column names in the first field_group will be used as labels in the view.
78
+ # so for { "ID" => ["lead_id", "user_id"] }
79
+ # the labels are the array ["lead_id","user_id"]
80
+ @labels = if @field_groups.first
81
+ @field_groups.first[1]
82
+ else
83
+ []
84
+ end
85
+ end
81
86
  end
82
87
 
83
88
  def fill_rows
@@ -12,9 +12,9 @@ module LetterGroup
12
12
  DEFAULT_SELECTED = ("a".."c").to_a.freeze
13
13
  IN_GROUPS = ALPHABET_AND_OTHER.each_slice(3)
14
14
 
15
- attr_reader :array_of_hashes, :groups, :total_selected, :selected
15
+ attr_reader :array_of_hashes, :groups, :total_selected, :selected, :labels
16
16
 
17
- def initialize(array_of_hashes = [], alpha_key:, unique_key:, selected: nil, field_groups: {})
17
+ def initialize(array_of_hashes = [], alpha_key:, unique_key:, selected: nil, field_groups: {}, labels: true)
18
18
  # With this sort of data triage many of the result rows must be combined to represent a single data issue.
19
19
  # (the nature of SQL JOINS)
20
20
  # Thus we can only get a count by tallying up the total for each group.
@@ -27,6 +27,7 @@ module LetterGroup
27
27
  raise ArgumentError, "#{self.class} Looks like unique_key (#{@unique_key} was not part of the select on fields: #{@fields.inspect}" unless @fields.empty? || @fields.include?(@unique_key)
28
28
  @field_groups = field_groups || {}
29
29
  @groups = {}
30
+ @labels = labels
30
31
  divide_into_letters
31
32
  set_selected(selected)
32
33
  @total_selected = each.inject(0) {|memo, group| memo += group.total; memo }
@@ -67,7 +68,8 @@ module LetterGroup
67
68
  letter: letter,
68
69
  unique_key: @unique_key,
69
70
  fields: @fields,
70
- field_groups: @field_groups
71
+ field_groups: @field_groups,
72
+ labels: labels
71
73
  )
72
74
  end
73
75
  rows, @array_of_hashes = @array_of_hashes.partition do |_|
@@ -1,3 +1,3 @@
1
1
  module LetterGroup
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-08 00:00:00.000000000 Z
11
+ date: 2015-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler