code_ape 2.0.2 → 3.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 +4 -4
- data/lib/code_ape/class.rb +54 -0
- data/lib/code_ape/constants.rb +6 -0
- data/lib/code_ape/division.rb +45 -0
- data/lib/code_ape/group.rb +45 -0
- data/lib/code_ape/section.rb +42 -0
- data/lib/code_ape/subsection.rb +45 -0
- data/lib/code_ape/version.rb +2 -1
- data/lib/code_ape.rb +27 -28
- data/lib/naf_rev2.json +6143 -0
- metadata +22 -54
- data/.gitignore +0 -8
- data/.travis.yml +0 -5
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -22
- data/README.md +0 -66
- data/Rakefile +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/code_ape.gemspec +0 -25
- data/lib/code_ape.yml +0 -1506
- data/lib/division_ape.yml +0 -180
- data/lib/naf_rev2.yml +0 -3458
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e09df670abbb4f129bfd0d7863ae2b7a18e0465fe1430ba6fa0dfa1257f7e1f0
|
4
|
+
data.tar.gz: 65c006c76b7cc4cf8a7eea854399a656341ef50bfabb15ceb1bf0d0b9c8aedbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cec0f4acc73693ca049d9ee78056c868cdb85091e71be78f4b8ee81fea8347885dba5bd6007571d32f36ba240ab855919d2de6c1c77468494c8f3d73f62d5f3d
|
7
|
+
data.tar.gz: ee3058ecd2cd103ada9c53a340b48a6708d921531175dc39ea9a70e8e678b1e0cfd1b58c83e486ecab382f65e3eddbaedc28027686c15b2725811a7f363aee32
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module CodeApe
|
2
|
+
# Regex to parse ape code class (notably in {CodeApe#ape})
|
3
|
+
REGEX_CLASS = /\A(\d{2})\.?(\d{2})([A-Z])\z/i
|
4
|
+
|
5
|
+
# Represent final ape code (all digits + letter)
|
6
|
+
class Class
|
7
|
+
attr_reader :key, :label
|
8
|
+
attr_reader :group_key, :division_key, :subsection_key, :section_key
|
9
|
+
|
10
|
+
# Creates a new {Class}
|
11
|
+
# @param key [Symbol, String] The class key of ape code
|
12
|
+
# @param label [String] The class label of ape code
|
13
|
+
# @param section_key [Symbol, String] The section key of ape code
|
14
|
+
# @param subsection_key [Symbol, String] The subsection key of ape code
|
15
|
+
# @param division_key [Symbol, String] The division key of ape code
|
16
|
+
# @param group_key [Symbol, String] The group key of ape code
|
17
|
+
def initialize(key, label, section_key, subsection_key, division_key, group_key)
|
18
|
+
@key = key.to_s
|
19
|
+
@label = label
|
20
|
+
@section_key = section_key.to_s
|
21
|
+
@subsection_key = subsection_key.to_s
|
22
|
+
@division_key = division_key.to_s
|
23
|
+
@group_key = group_key.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [CodeApe::Group] the group of this ape code
|
27
|
+
def group
|
28
|
+
@group ||= GROUPS.find { |e| e.key == @group_key }
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [CodeApe::Division] the division of this ape code
|
32
|
+
def division
|
33
|
+
@division ||= DIVISIONS.find { |e| e.key == @division_key }
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [CodeApe::Subsection] the subsection of this ape code
|
37
|
+
def subsection
|
38
|
+
@subsection ||= SUBSECTIONS.find { |e| e.key == @subsection_key }
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [CodeApe::Section] the section of this ape code
|
42
|
+
def section
|
43
|
+
@section ||= SECTIONS.find { |e| e.key == @section_key }
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Hash] the hash representation of class label
|
47
|
+
def to_h
|
48
|
+
{label: @label}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# List of ape code classes
|
53
|
+
CLASSES = NAF_REV2[:classes].map { |k, v| Class.new(k, v[:label], v[:section], v[:subsection], v[:division], v[:group]) }.freeze
|
54
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module CodeApe
|
2
|
+
# Regex to parse ape code division (notably in {CodeApe#ape})
|
3
|
+
REGEX_DIVISION = /\A(\d{2})\.?(\d{1})\z/i
|
4
|
+
|
5
|
+
# Represent division of ape code (first 3 digits)
|
6
|
+
class Division
|
7
|
+
attr_reader :key, :label
|
8
|
+
|
9
|
+
# Creates a new {Division}
|
10
|
+
# @param key [Symbol, String] The division key of ape code
|
11
|
+
# @param label [String] The division label of ape code
|
12
|
+
def initialize(key, label)
|
13
|
+
@key = key.to_s
|
14
|
+
@label = label
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Array<CodeApe::Class>] the classes associated with division of this ape code
|
18
|
+
def classes
|
19
|
+
@classes ||= CLASSES.select { |e| e.division_key == @key }
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Array<CodeApe::Group>] the groups associated with division of this ape code
|
23
|
+
def groups
|
24
|
+
@groups ||= GROUPS.select { |e| classes.map(&:group_key).include?(e.key) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [CodeApe::Subsection] the subsection of this ape code
|
28
|
+
def subsection
|
29
|
+
@subsection ||= SUBSECTIONS.find { |e| e.key == classes[0]&.subsection_key }
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [CodeApe::Section] the section of this ape code
|
33
|
+
def section
|
34
|
+
@section ||= SECTIONS.find { |e| e.key == classes[0]&.section_key }
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Hash] the hash representation of division label
|
38
|
+
def to_h
|
39
|
+
{label: @label}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# List of ape code divisions
|
44
|
+
DIVISIONS = NAF_REV2[:divisions].map { |k, v| Division.new(k, v) }.freeze
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module CodeApe
|
2
|
+
# Regex to parse ape code group (notably in {CodeApe#ape})
|
3
|
+
REGEX_GROUP = /\A(\d{2})\.?(\d{2})\z/i
|
4
|
+
|
5
|
+
# Represent group of ape code (all digits)
|
6
|
+
class Group
|
7
|
+
attr_reader :key, :label
|
8
|
+
|
9
|
+
# Creates a new {Group}
|
10
|
+
# @param key [Symbol, String] The group key of ape code
|
11
|
+
# @param label [String] The group label of ape code
|
12
|
+
def initialize(key, label)
|
13
|
+
@key = key.to_s
|
14
|
+
@label = label
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Array<CodeApe::Class>] the classes associated with group of this ape code
|
18
|
+
def classes
|
19
|
+
@classes ||= CLASSES.select { |e| e.group_key == @key }
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [CodeApe::Division] the division of this ape code
|
23
|
+
def division
|
24
|
+
@division ||= DIVISIONS.find { |e| e.key == classes[0]&.division_key }
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [CodeApe::Subsection] the subsection of this ape code
|
28
|
+
def subsection
|
29
|
+
@subsection ||= SUBSECTIONS.find { |e| e.key == classes[0]&.subsection_key }
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [CodeApe::Section] the section of this ape code
|
33
|
+
def section
|
34
|
+
@section ||= SECTIONS.find { |e| e.key == classes[0]&.section_key }
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Hash] the hash representation of group label
|
38
|
+
def to_h
|
39
|
+
{label: @label}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# List of ape code groups
|
44
|
+
GROUPS = NAF_REV2[:groups].map { |k, v| Group.new(k, v) }.freeze
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module CodeApe
|
2
|
+
# Represent section of ape code (A letter assigned to a subdivision grouping not represented in the final ape code)
|
3
|
+
class Section
|
4
|
+
attr_reader :key, :label
|
5
|
+
|
6
|
+
# Creates a new {Section}
|
7
|
+
# @param key [Symbol, String] The section key of ape code
|
8
|
+
# @param label [String] The section label of ape code
|
9
|
+
def initialize(key, label)
|
10
|
+
@key = key.to_s
|
11
|
+
@label = label
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Array<CodeApe::Class>] the classes associated with section of this ape code
|
15
|
+
def classes
|
16
|
+
@classes ||= CLASSES.select { |e| e.section_key == @key }
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array<CodeApe::Group>] the groups associated with section of this ape code
|
20
|
+
def groups
|
21
|
+
@groups ||= GROUPS.select { |e| classes.map(&:group_key).include?(e.key) }
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Array<CodeApe::Division>] the divisions associated with section of this ape code
|
25
|
+
def divisions
|
26
|
+
@divisions ||= DIVISIONS.select { |e| classes.map(&:division_key).include?(e.key) }
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Array<CodeApe::Subsection>] the subsections associated with section of this ape code
|
30
|
+
def subsections
|
31
|
+
@subsections ||= SUBSECTIONS.select { |e| classes.map(&:subsection_key).include?(e.key) }
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Hash] the hash representation of section label
|
35
|
+
def to_h
|
36
|
+
{label: @label}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# List of ape code sections
|
41
|
+
SECTIONS = NAF_REV2[:sections].map { |k, v| Section.new(k, v) }.freeze
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module CodeApe
|
2
|
+
# Regex to parse ape code subsection (notably in {CodeApe#ape})
|
3
|
+
REGEX_SUBSECTION = /\A(\d{2})\z/i
|
4
|
+
|
5
|
+
# Represent subsection of ape code (first 2 digits)
|
6
|
+
class Subsection
|
7
|
+
attr_reader :key, :label
|
8
|
+
|
9
|
+
# Creates a new {Subsection}
|
10
|
+
# @param key [Symbol, String] The subsection key of ape code
|
11
|
+
# @param label [String] The subsection label of ape code
|
12
|
+
def initialize(key, label)
|
13
|
+
@key = key.to_s
|
14
|
+
@label = label
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Array<CodeApe::Class>] the classes associated with subsection of this ape code
|
18
|
+
def classes
|
19
|
+
@classes ||= CLASSES.select { |e| e.subsection_key == @key }
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Array<CodeApe::Group>] the groups associated with subsection of this ape code
|
23
|
+
def groups
|
24
|
+
@groups ||= GROUPS.select { |e| classes.map(&:group_key).include?(e.key) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Array<CodeApe::Division>] the divisions associated with subsection of this ape code
|
28
|
+
def divisions
|
29
|
+
@divisions ||= DIVISIONS.select { |e| classes.map(&:division_key).include?(e.key) }
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [CodeApe::Section] the section of this ape code
|
33
|
+
def section
|
34
|
+
@section ||= SECTIONS.find { |e| e.key == classes[0]&.section_key }
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Hash] the hash representation of subsection label
|
38
|
+
def to_h
|
39
|
+
{label: @label}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# List of ape code subsections
|
44
|
+
SUBSECTIONS = NAF_REV2[:subsections].map { |k, v| Subsection.new(k, v) }.freeze
|
45
|
+
end
|
data/lib/code_ape/version.rb
CHANGED
data/lib/code_ape.rb
CHANGED
@@ -1,38 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require "code_ape/version"
|
2
2
|
|
3
|
-
require
|
3
|
+
require "code_ape/constants"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
CODE_APE ||= YAML.load_file(File.join(File.dirname(__FILE__), 'code_ape.yml'))
|
5
|
+
require "code_ape/section"
|
6
|
+
require "code_ape/subsection"
|
7
|
+
require "code_ape/division"
|
8
|
+
require "code_ape/group"
|
9
|
+
require "code_ape/class"
|
11
10
|
|
11
|
+
# All CodeApe functionality
|
12
|
+
module CodeApe
|
13
|
+
# Takes a ape code and returns data if possible
|
14
|
+
# @param code [String] The ape code to search
|
15
|
+
# @return [CodeApe::Subsection, CodeApe::Division, CodeApe::Group, CodeApe::Class, nil] the ape code data
|
12
16
|
def self.ape(code)
|
13
|
-
|
14
|
-
NAF_REV2[code.to_s]
|
15
|
-
else
|
16
|
-
nil
|
17
|
-
end
|
18
|
-
end
|
17
|
+
upcased_code = code&.upcase
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
case upcased_code
|
20
|
+
when REGEX_SUBSECTION
|
21
|
+
SUBSECTIONS.find { |e| e.key == upcased_code }
|
22
|
+
when REGEX_DIVISION
|
23
|
+
DIVISIONS.find { |e| e.key == upcased_code || e.key.delete(".") == upcased_code }
|
24
|
+
when REGEX_GROUP
|
25
|
+
GROUPS.find { |e| e.key == upcased_code || e.key.delete(".") == upcased_code }
|
26
|
+
when REGEX_CLASS
|
27
|
+
CLASSES.find { |e| e.key == upcased_code || e.key.delete(".") == upcased_code }
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
nil
|
35
|
-
end
|
31
|
+
# Takes a section code and returns data if possible
|
32
|
+
# @param code [String] The section code to search
|
33
|
+
# @return [CodeApe::Section, nil] the section code data
|
34
|
+
def self.section(code)
|
35
|
+
SECTIONS.find { |e| e.key == code&.upcase }
|
36
36
|
end
|
37
|
-
|
38
37
|
end
|