competitor-mention-tally 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: 6a3b244bb4933dfc19d8dda372082a8066cd9ad43f99b2b56e8cee5356d0e808
4
+ data.tar.gz: 6199c8d8c4c986f2018a0433c310e8dac69d6d0d67bce8dfb815d60ebcb56e28
5
+ SHA512:
6
+ metadata.gz: f8012b09946fda9e8d3e24b9e32e93da50a3e2b2ed1f42717554cbeae8fb1e9388f1b7fbaad9ae587c5705854ecc9b1b06daa69e58da63fe9011cb021513ba02
7
+ data.tar.gz: c377ce6e65b41ffa798229abcd3cf4c0d6723f17cf34ada43e93b6a39650d4b3549a3e9fa3607ef631341b4e95140ee6db1d419b53448adafad3d81e8dd411dd
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,35 @@
1
+ # competitor-mention-tally
2
+
3
+ Ruby command line tool and library. Give it a CSV of deal notes and a list of competitors and it counts how many deals name each competitor, how many times each is mentioned, how many deals name at least one competitor and how many name two or more.
4
+
5
+ Part of the [OneGTMLab](https://www.onegtmlab.dev) free GTM tools. Background on the idea: [competitive intelligence](https://www.onegtmlab.dev/glossary/competitive-intelligence).
6
+
7
+ ## Install
8
+
9
+ ```
10
+ gem install competitor-mention-tally
11
+ ```
12
+
13
+ ## Use
14
+
15
+ CSV columns: deal_id, notes. Pass the competitors with --competitors: commas separate competitors, a | separates aliases of one competitor, and the first alias is the display name (Alpha|Alpha Cloud,Beta,Gamma is three competitors). Matching is case-insensitive and whole word, so a note that says Betamax does not count as Beta. A competitor's longer aliases are tried first, so Alpha Cloud counts as one mention of Alpha, not two. Each competitor is counted on its own, so a note can count for several competitors. Rows that share a deal_id are one deal. Output is sorted by deals, most first, then by name; shares are a percentage of all deals. A missing file, a missing column or no competitors stops the run with an error and a non-zero exit code.
16
+
17
+ ```
18
+ $ ruby bin/competitor-mention-tally sample.csv --competitors "Alpha|Alpha Cloud,Beta,Gamma"
19
+ deals: 8
20
+ deals naming at least one competitor: 5 (62.5%)
21
+ deals naming two or more competitors: 2 (25.0%)
22
+
23
+ competitor deals share mentions
24
+ Alpha 3 37.5% 4
25
+ Beta 3 37.5% 4
26
+ Gamma 2 25.0% 2
27
+ ```
28
+
29
+ ## Test
30
+
31
+ ```
32
+ ruby test/run.rb
33
+ ```
34
+
35
+ Offline, no network calls, no dependencies beyond the language runtime. MIT licensed.
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/competitor_mention_tally'
5
+
6
+ if ARGV.empty? || ARGV.include?('-h') || ARGV.include?('--help')
7
+ warn "usage: competitor-mention-tally deals.csv --competitors \"Alpha|Alpha Cloud,Beta,Gamma\"\n" \
8
+ "CSV columns: deal_id, notes. Commas separate competitors, | separates aliases of one. More: https://www.onegtmlab.dev/glossary/competitive-intelligence"
9
+ exit 2
10
+ end
11
+
12
+ begin
13
+ path, text = CompetitorMentionTally.parse_args(ARGV)
14
+ competitors = CompetitorMentionTally.parse_competitors(text)
15
+ deals = CompetitorMentionTally.from_csv(File.read(path))
16
+ print CompetitorMentionTally.render(CompetitorMentionTally.tally(deals, competitors))
17
+ rescue ArgumentError, Errno::ENOENT, Errno::EISDIR, CSV::MalformedCSVError => e
18
+ abort "error: #{e.message}"
19
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ # Count which competitors are named in deal notes.
6
+ module CompetitorMentionTally
7
+ Competitor = Struct.new(:name, :pattern, keyword_init: true)
8
+ Tally = Struct.new(:name, :deals, :mentions, keyword_init: true)
9
+
10
+ # "Alpha|Alpha Cloud,Beta,Gamma" => competitors separated by commas, aliases by |.
11
+ # The first alias is the display name. Longer aliases are tried first so that
12
+ # "Alpha Cloud" is one mention, not two.
13
+ def self.parse_competitors(text)
14
+ list = text.to_s.split(',').map { |part| part.split('|').map(&:strip).reject(&:empty?) }.reject(&:empty?)
15
+ raise ArgumentError, 'no competitors given' if list.empty?
16
+
17
+ list.map do |aliases|
18
+ alt = aliases.sort_by { |a| -a.length }.map { |a| Regexp.escape(a) }.join('|')
19
+ # Whole word: not preceded or followed by a letter, digit or underscore.
20
+ pattern = /(?<![[:alnum:]_])(?:#{alt})(?![[:alnum:]_])/i
21
+ Competitor.new(name: aliases.first, pattern: pattern)
22
+ end
23
+ end
24
+
25
+ # Returns a hash { deal_id => notes } in file order. Rows with the same deal_id are joined.
26
+ def self.from_csv(text)
27
+ table = CSV.parse(text, headers: true)
28
+ missing = %w[deal_id notes] - table.headers.compact.map(&:strip)
29
+ raise ArgumentError, "missing column(s): #{missing.join(', ')}" unless missing.empty?
30
+ raise ArgumentError, 'no rows in the CSV' if table.empty?
31
+
32
+ deals = {}
33
+ table.each_with_index do |r, i|
34
+ id = r['deal_id'].to_s.strip
35
+ raise ArgumentError, "line #{i + 2}: empty deal_id" if id.empty?
36
+
37
+ deals[id] = [deals[id], r['notes'].to_s].compact.join("\n")
38
+ end
39
+ deals
40
+ end
41
+
42
+ # Returns { deals:, with_any:, with_two_plus:, rows: [Tally, ...] } sorted by deals desc, then name.
43
+ def self.tally(deals, competitors)
44
+ per_deal = deals.transform_values do |notes|
45
+ competitors.to_h { |c| [c.name, notes.scan(c.pattern).size] }
46
+ end
47
+ named = per_deal.values.map { |counts| counts.count { |_, n| n.positive? } }
48
+ rows = competitors.map do |c|
49
+ Tally.new(name: c.name,
50
+ deals: per_deal.values.count { |counts| counts[c.name].positive? },
51
+ mentions: per_deal.values.sum { |counts| counts[c.name] })
52
+ end
53
+ { deals: deals.size, with_any: named.count(&:positive?), with_two_plus: named.count { |n| n >= 2 },
54
+ rows: rows.sort_by { |t| [-t.deals, t.name] } }
55
+ end
56
+
57
+ def self.pct(part, whole)
58
+ format('%.1f%%', part * 100.0 / whole)
59
+ end
60
+
61
+ def self.render(result)
62
+ total = result[:deals]
63
+ out = +"deals: #{total}\n"
64
+ out << "deals naming at least one competitor: #{result[:with_any]} (#{pct(result[:with_any], total)})\n"
65
+ out << "deals naming two or more competitors: #{result[:with_two_plus]} (#{pct(result[:with_two_plus], total)})\n\n"
66
+ width = [result[:rows].map { |t| t.name.length }.max, 10].max
67
+ out << format("%-#{width}s %5s %7s %9s\n", 'competitor', 'deals', 'share', 'mentions')
68
+ result[:rows].each do |t|
69
+ out << format("%-#{width}s %5d %7s %9d\n", t.name, t.deals, pct(t.deals, total), t.mentions)
70
+ end
71
+ out
72
+ end
73
+
74
+ # Parse the command line. Returns [path, competitors_text]; raises ArgumentError on bad input.
75
+ def self.parse_args(argv)
76
+ args = argv.dup
77
+ path = nil
78
+ competitors = nil
79
+ until args.empty?
80
+ arg = args.shift
81
+ case arg
82
+ when '--competitors'
83
+ raise ArgumentError, '--competitors needs a value' if args.empty?
84
+
85
+ competitors = args.shift
86
+ when /\A-/ then raise ArgumentError, "unknown option #{arg}"
87
+ else
88
+ raise ArgumentError, "unexpected extra argument #{arg.inspect}" if path
89
+
90
+ path = arg
91
+ end
92
+ end
93
+ raise ArgumentError, 'no CSV file given' unless path
94
+ raise ArgumentError, 'no competitors given, use --competitors "Alpha|Alpha Cloud,Beta"' if competitors.nil?
95
+
96
+ [path, competitors]
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: competitor-mention-tally
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 deal notes and a list of competitors with aliases, count whole-word, case-insensitive mentions, the deals that name each competitor, and the deals that name two or more. Offline."
29
+ executables:
30
+ - competitor-mention-tally
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - bin/competitor-mention-tally
37
+ - lib/competitor_mention_tally.rb
38
+ homepage: "https://www.onegtmlab.dev/glossary/competitive-intelligence"
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ source_code_uri: "https://github.com/jaizendra-netizen/competitor-mention-tally"
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ -
49
+ - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "2.7"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ -
55
+ - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ requirements: []
59
+ rubygems_version: 4.1.0
60
+ specification_version: 4
61
+ summary: Count how many deals mention each competitor in the deal notes
62
+ test_files: []