effective_reports 0.1.2 → 0.1.3

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
  SHA256:
3
- metadata.gz: 4a0eb1f2073ced73e4323f8bbf4996fa42bd1f275954ce4fd0cd880f06924555
4
- data.tar.gz: 8b05f4cc6d5f8c62f9b749427997e4cb376902a069e817acd9eb98aadf83a671
3
+ metadata.gz: 991d7b212a5902f3a50a65e1a9ab6261772f610d5b9c34fd531cd42d8fc8dd21
4
+ data.tar.gz: 880c5838c51e1f53fa71549d578e290f3b09c70388f0351d8d9b47972829afae
5
5
  SHA512:
6
- metadata.gz: 67febf40c58be31ded2a04f14e64514763ddccd5dc83eb1f02aba5de72144d5034a9382d4f3aabfcdeecacac1b6403c14a6eadd971cc953c732215a1a4d70490
7
- data.tar.gz: 1fabf86d60be49374c15bbfd4e66cb52fc96e2f05bee11d8820532550007df2e21daa3945b2173b4faa48bdb7f208a3f81f6c66e114075656c2069cbb976d9fb
6
+ metadata.gz: 35c55dd39bc05eaf96a9308ba9193f9f188fd5248f1c3f31b8398c20cae3fc110bf15156fc8d6696ab4f16a6ba5f9b30d3ccab8c15b1f048805173f9bb90080d
7
+ data.tar.gz: 639050630369e02d01d5fcb7e43019d70f1d96b03e5ccb24dc32cad0ac6b051ba5a20f73d1c8feb3253d6200c3fad47bc98715d18cef9f05237691b0f09efacf
@@ -26,6 +26,7 @@ module Effective
26
26
 
27
27
  scope :deep, -> { includes(:report_columns, :report_scopes) }
28
28
  scope :sorted, -> { order(:title) }
29
+ scope :emails, -> { where(id: ReportColumn.emails.select(:report_id)) }
29
30
 
30
31
  validates :title, presence: true, uniqueness: true
31
32
  validates :reportable_class_name, presence: true
@@ -42,6 +43,10 @@ module Effective
42
43
  report_columns.select(&:filter?)
43
44
  end
44
45
 
46
+ def email_report_column
47
+ report_columns.find { |column| column.name.include?('email') }
48
+ end
49
+
45
50
  # Used to build the Reports form
46
51
  # { id: :integer, archived: :boolean }
47
52
  def reportable_attributes
@@ -27,6 +27,7 @@ module Effective
27
27
 
28
28
  scope :deep, -> { includes(:report) }
29
29
  scope :sorted, -> { order(:position) }
30
+ scope :emails, -> { where('name ILIKE ?', "%email%") }
30
31
 
31
32
  before_validation(if: -> { report.present? }) do
32
33
  self.position ||= (report.report_columns.map(&:position).compact.max || -1) + 1
@@ -57,6 +58,25 @@ module Effective
57
58
  [name, operation_label, value].compact.join(' ').presence || 'report column'
58
59
  end
59
60
 
61
+ def format(value)
62
+ return '' if value.blank?
63
+
64
+ case as.to_sym
65
+ when :boolean then value.to_s
66
+ when :date then value.strftime('%F')
67
+ when :decimal then value.to_s
68
+ when :integer then value.to_s
69
+ when :price then '$' + ('%0.2f' % (value / 100.0))
70
+ when :string then value.to_s
71
+ when :belongs_to then value.to_s
72
+ when :belongs_to_polymorphic then value.to_s
73
+ when :has_many then Array(value).map { |value| value.to_s }.join("\n\n")
74
+ when :has_one then value.to_s
75
+ else
76
+ raise("unexpected as: #{as || 'nil'}")
77
+ end
78
+ end
79
+
60
80
  def as_associated?
61
81
  [:belongs_to, :belongs_to_polymorphic, :has_many, :has_one].include?(as.to_sym)
62
82
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveReports
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-19 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails