Class: CodeApe::Subsection

Inherits:
Object
  • Object
show all
Defined in:
lib/code_ape/subsection.rb

Overview

Represent subsection of ape code (first 2 digits)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, label) ⇒ Subsection

Creates a new CodeApe::Subsection

Parameters:

  • key (Symbol, String)

    The subsection key of ape code

  • label (String)

    The subsection label of ape code



12
13
14
15
# File 'lib/code_ape/subsection.rb', line 12

def initialize(key, label)
  @key = key.to_s
  @label = label
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/code_ape/subsection.rb', line 7

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/code_ape/subsection.rb', line 7

def label
  @label
end

Instance Method Details

#classesArray<CodeApe::Class>

Returns the classes associated with subsection of this ape code.

Returns:

  • (Array<CodeApe::Class>)

    the classes associated with subsection of this ape code



18
19
20
# File 'lib/code_ape/subsection.rb', line 18

def classes
  @classes ||= CLASSES.select { |e| e.subsection_key == @key }
end

#divisionsArray<CodeApe::Division>

Returns the divisions associated with subsection of this ape code.

Returns:

  • (Array<CodeApe::Division>)

    the divisions associated with subsection of this ape code



28
29
30
# File 'lib/code_ape/subsection.rb', line 28

def divisions
  @divisions ||= DIVISIONS.select { |e| classes.map(&:division_key).include?(e.key) }
end

#groupsArray<CodeApe::Group>

Returns the groups associated with subsection of this ape code.

Returns:

  • (Array<CodeApe::Group>)

    the groups associated with subsection of this ape code



23
24
25
# File 'lib/code_ape/subsection.rb', line 23

def groups
  @groups ||= GROUPS.select { |e| classes.map(&:group_key).include?(e.key) }
end

#sectionCodeApe::Section

Returns the section of this ape code.

Returns:



33
34
35
# File 'lib/code_ape/subsection.rb', line 33

def section
  @section ||= SECTIONS.find { |e| e.key == classes[0]&.section_key }
end

#to_hHash

Returns the hash representation of subsection label.

Returns:

  • (Hash)

    the hash representation of subsection label



38
39
40
# File 'lib/code_ape/subsection.rb', line 38

def to_h
  {label: @label}
end