coconductor 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coconductor/code_of_conduct.rb +1 -2
- data/lib/coconductor/field.rb +78 -0
- data/lib/coconductor/matchers/field_aware.rb +1 -1
- data/lib/coconductor/version.rb +1 -1
- data/lib/coconductor.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05bb04085f2577f27816fad8a5c2fe21772401516f3e245d238aa8bf97437f31
|
4
|
+
data.tar.gz: 5cd56a968556c68e4c527ca53cced7a20e2869d3cfd5d70dd02d7d37b432d543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3815b1990aca73057b3442225327a6002772bbc8b5e02f2fab024346166c92de713b64befd5bacdf3e215048cb9407df1ebdf748c8efaeb3f1cfefd250084c9b
|
7
|
+
data.tar.gz: c2714f37217cd29b5b2e0efb794c06fe4d5e86bd2ed4f4b64f0af16124688c5a7870fa950f08bd06b0f203d4f159c7aeaf63e89a58028ff6cedf65eb74a0f53c
|
@@ -64,7 +64,6 @@ module Coconductor
|
|
64
64
|
/(?<major>\d)/(?<minor>\d)(/(?<patch>\d))?
|
65
65
|
/#{Coconductor::ProjectFiles::CodeOfConductFile::FILENAME_REGEX}
|
66
66
|
}ix
|
67
|
-
FIELD_REGEX = /\[(?<name>[A-Z_ ]{2,}).*\]/
|
68
67
|
|
69
68
|
attr_reader :key
|
70
69
|
attr_writer :content
|
@@ -125,7 +124,7 @@ module Coconductor
|
|
125
124
|
end
|
126
125
|
|
127
126
|
def fields
|
128
|
-
|
127
|
+
@fields ||= Field.from_code_of_conduct(self)
|
129
128
|
end
|
130
129
|
|
131
130
|
private
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Coconductor
|
2
|
+
# Represents a fillable field in a code of conduct
|
3
|
+
class Field
|
4
|
+
REGEX = /\[(?<name>[A-Z_ ]{2,}):?\s?(?<description>.*)\]/
|
5
|
+
|
6
|
+
# the matchable raw text within the code of conduct including brackets
|
7
|
+
attr_reader :raw_text
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Returns an array of Fields for the given code of conduct
|
11
|
+
def from_code_of_conduct(code_of_conduct)
|
12
|
+
matches = []
|
13
|
+
|
14
|
+
code_of_conduct.content.scan(REGEX) do |_m|
|
15
|
+
matches << Regexp.last_match
|
16
|
+
end
|
17
|
+
|
18
|
+
fields = matches.map do |m|
|
19
|
+
new(m[0], name: m[:name], description: m[:description])
|
20
|
+
end
|
21
|
+
|
22
|
+
fields.uniq(&:key)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns all fields accross all vendored codes of conduct
|
26
|
+
def all
|
27
|
+
@all ||= CodeOfConduct.latest.map(&:fields).flatten.uniq(&:key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(raw_text, name: nil, description: nil)
|
32
|
+
@raw_text = raw_text
|
33
|
+
@name = name
|
34
|
+
@description = description
|
35
|
+
end
|
36
|
+
|
37
|
+
# The unformatted field name as found in the code of conduct text
|
38
|
+
def name
|
39
|
+
@name ||= parts ? parts[:name].strip : nil
|
40
|
+
end
|
41
|
+
|
42
|
+
# human readable label
|
43
|
+
def label
|
44
|
+
@label ||= normalized_name.downcase.tr('_', ' ').capitalize
|
45
|
+
end
|
46
|
+
|
47
|
+
# machine readable key
|
48
|
+
def key
|
49
|
+
@key ||= normalized_name.downcase
|
50
|
+
end
|
51
|
+
|
52
|
+
def description
|
53
|
+
@description ||= parts ? parts[:description] : nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def inspect
|
57
|
+
methods = %w[name key label]
|
58
|
+
kvs = methods.map { |method| [method, public_send(method)] }.to_h
|
59
|
+
kvs = kvs.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
|
60
|
+
"<Coconductor::Field #{kvs}>"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def parts
|
66
|
+
@parts ||= raw_text.match(REGEX)
|
67
|
+
end
|
68
|
+
|
69
|
+
def normalized_name
|
70
|
+
@normalized_name ||= begin
|
71
|
+
normalized_name = name.tr(' ', '_')
|
72
|
+
normalized_name = normalized_name.gsub(/\A(YOUR|INSERT)_/i, '')
|
73
|
+
normalized_name = normalized_name.gsub(/_?HERE\z/i, '')
|
74
|
+
normalized_name.strip
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -23,7 +23,7 @@ module Coconductor
|
|
23
23
|
coc = code_of_conduct.dup
|
24
24
|
coc.instance_variable_set '@content_normalized', nil
|
25
25
|
coc.instance_variable_set '@content_without_title_and_version', nil
|
26
|
-
field_regex =
|
26
|
+
field_regex = /#{Regexp.union(coc.fields.map(&:raw_text))}/i
|
27
27
|
coc.content = coc.content.gsub(field_regex, FIELD_PLACEHOLDER)
|
28
28
|
regex = Regexp.escape(coc.content_normalized)
|
29
29
|
regex = regex.gsub(FIELD_PLACEHOLDER_REGEX, '([a-z ]+?)')
|
data/lib/coconductor/version.rb
CHANGED
data/lib/coconductor.rb
CHANGED
@@ -3,6 +3,7 @@ require 'licensee'
|
|
3
3
|
|
4
4
|
module Coconductor
|
5
5
|
autoload :CodeOfConduct, 'coconductor/code_of_conduct'
|
6
|
+
autoload :Field, 'coconductor/field'
|
6
7
|
autoload :Matchers, 'coconductor/matchers'
|
7
8
|
autoload :Projects, 'coconductor/projects'
|
8
9
|
autoload :ProjectFiles, 'coconductor/project_files'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coconductor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/coconductor/commands/detect.rb
|
161
161
|
- lib/coconductor/commands/diff.rb
|
162
162
|
- lib/coconductor/commands/version.rb
|
163
|
+
- lib/coconductor/field.rb
|
163
164
|
- lib/coconductor/matchers.rb
|
164
165
|
- lib/coconductor/matchers/dice.rb
|
165
166
|
- lib/coconductor/matchers/exact.rb
|