trigger-event-freshness 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 70bfce643a4a12a1151cc1a154ee5f47206a78fcddef9e1f1c00ee666dc39f89
4
+ data.tar.gz: 8e31952289239aac39df36a25befb77284da9a19b42498a686228382787d1c39
5
+ SHA512:
6
+ metadata.gz: 6ffd71bc61b5f34122b4709f4f2a3627d8862aea02f44533e3b61d0f7a36554e38ccb61141f0c4be21fea9ea7f87bae7e139fbb089979f8d7da1ebc5588176ef
7
+ data.tar.gz: 933d673fd78eb9c9d3e24be0583a77dc8105db9c8538eae7baca3d0dcd37a79054864d8aebad13d5f996fd5f54f570e8f9277b863f991d2ba3eadebaeb2f4780
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OneGTMLab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # trigger-event-freshness
2
+
3
+ Ruby command line tool and library. Give it a CSV of trigger events (funding, hiring, leadership change) with the date you saw each one and it shows how many days old each is and whether it is still inside your act-by window: fresh, aging (up to 1.5 times the window) or stale. Windows are yours to set.
4
+
5
+ Part of the [OneGTMLab](https://www.onegtmlab.dev) free GTM tools. Background on the idea: [trigger event](https://www.onegtmlab.dev/glossary/trigger-event).
6
+
7
+ ## Install
8
+
9
+ ```
10
+ gem install trigger-event-freshness
11
+ ```
12
+
13
+ ## Use
14
+
15
+ CSV columns: account, event, seen_on (YYYY-MM-DD). Default windows: funding 30, hiring 21, leadership_change 45 days, anything else 30. Change them with --windows.
16
+
17
+ ```
18
+ $ ruby bin/trigger-event-freshness sample.csv --as-of 2026-11-28
19
+ account event days status
20
+ Northwind funding 8 fresh
21
+ Umbrella podcast_mention 27 fresh
22
+ Acme Robotics hiring 29 aging
23
+ Initech funding 49 stale
24
+ Globex leadership_change 88 stale
25
+ fresh 2, aging 1, stale 2 of 5 events
26
+ ```
27
+
28
+ ## Test
29
+
30
+ ```
31
+ ruby test/run.rb
32
+ ```
33
+
34
+ Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/trigger_event_freshness'
5
+
6
+ args = ARGV.dup
7
+ if args.empty? || args.include?('-h') || args.include?('--help')
8
+ warn "usage: trigger-event-freshness events.csv [--as-of 2026-11-28] [--windows funding=30,hiring=21] [--default-days 30]\n" \
9
+ "CSV columns: account, event, seen_on (YYYY-MM-DD). More: https://www.onegtmlab.dev/glossary/trigger-event"
10
+ exit 2
11
+ end
12
+ file = args.shift
13
+ as_of = Date.today
14
+ windows = {}
15
+ default = 30
16
+ begin
17
+ until args.empty?
18
+ flag = args.shift
19
+ val = args.shift or abort "#{flag} needs a value"
20
+ case flag
21
+ when '--as-of' then as_of = Date.iso8601(val)
22
+ when '--windows' then windows = TriggerEventFreshness.parse_windows(val)
23
+ when '--default-days' then default = Integer(val)
24
+ else abort "unknown option #{flag}"
25
+ end
26
+ end
27
+ print TriggerEventFreshness.render(TriggerEventFreshness.from_csv(File.read(file), as_of, windows, default: default))
28
+ rescue ArgumentError, Date::Error, Errno::ENOENT => e
29
+ abort "error: #{e.message}"
30
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require 'date'
5
+
6
+ # Score how fresh each trigger event is against an act-by window you choose.
7
+ module TriggerEventFreshness
8
+ Row = Struct.new(:account, :event, :age_days, :status, keyword_init: true)
9
+ DEFAULT_WINDOWS = { 'funding' => 30, 'hiring' => 21, 'leadership_change' => 45 }.freeze
10
+
11
+ def self.parse_windows(text)
12
+ text.split(',').to_h do |pair|
13
+ k, v = pair.split('=', 2)
14
+ raise ArgumentError, "bad window #{pair.inspect}" if k.to_s.empty? || v.to_s !~ /\A\d+\z/
15
+
16
+ [k.strip, v.to_i]
17
+ end
18
+ end
19
+
20
+ # status: fresh (inside the window), aging (inside 1.5x), stale (beyond)
21
+ def self.status(age, window)
22
+ return 'fresh' if age <= window
23
+ return 'aging' if age <= window * 1.5
24
+
25
+ 'stale'
26
+ end
27
+
28
+ def self.from_csv(text, as_of, windows = {}, default: 30)
29
+ w = DEFAULT_WINDOWS.merge(windows)
30
+ rows = CSV.parse(text, headers: true).map do |r|
31
+ seen = Date.iso8601(r['seen_on'].to_s.strip)
32
+ age = (as_of - seen).to_i
33
+ raise ArgumentError, "seen_on is after as-of for #{r['account']}" if age.negative?
34
+
35
+ ev = r['event'].to_s.strip
36
+ Row.new(account: r['account'].to_s.strip, event: ev, age_days: age, status: status(age, w.fetch(ev, default)))
37
+ end
38
+ rows.sort_by { |r| [%w[fresh aging stale].index(r.status), r.age_days] }
39
+ end
40
+
41
+ def self.render(rows)
42
+ out = +format("%-18s %-18s %5s %s\n", 'account', 'event', 'days', 'status')
43
+ rows.each { |r| out << format("%-18s %-18s %5d %s\n", r.account, r.event, r.age_days, r.status) }
44
+ counts = rows.group_by(&:status).transform_values(&:size)
45
+ out << format("fresh %d, aging %d, stale %d of %d events\n", counts.fetch('fresh', 0), counts.fetch('aging', 0), counts.fetch('stale', 0), rows.size)
46
+ out
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trigger-event-freshness
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - OneGTMLab
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: csv
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "0"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: "0"
28
+ description: "Ruby CLI and library: from a CSV of trigger events (funding, hiring, leadership change) with the date you saw each one, show how many days old it is and whether it is still inside your act-by window. Offline."
29
+ email:
30
+ - account@onegtmlab.dev
31
+ executables:
32
+ - trigger-event-freshness
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - LICENSE
37
+ - README.md
38
+ - bin/trigger-event-freshness
39
+ - lib/trigger_event_freshness.rb
40
+ homepage: "https://www.onegtmlab.dev/glossary/trigger-event"
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ homepage_uri: "https://www.onegtmlab.dev/glossary/trigger-event"
45
+ source_code_uri: "https://github.com/jaizendra-netizen/trigger-event-freshness"
46
+ documentation_uri: "https://www.onegtmlab.dev/glossary/trigger-event"
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ -
53
+ - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "2.7"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ -
59
+ - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ requirements: []
63
+ rubygems_version: 4.1.0
64
+ specification_version: 4
65
+ summary: "Rate each trigger event as fresh, aging or stale against an act-by window per event type"
66
+ test_files: []