Class: CodeApe::Group

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

Overview

Represent group of ape code (all digits)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, label) ⇒ Group

Creates a new CodeApe::Group

Parameters:

  • key (Symbol, String)

    The group key of ape code

  • label (String)

    The group label of ape code



12
13
14
15
# File 'lib/code_ape/group.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/group.rb', line 7

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

Instance Method Details

#classesArray<CodeApe::Class>

Returns the classes associated with group of this ape code.

Returns:

  • (Array<CodeApe::Class>)

    the classes associated with group of this ape code



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

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

#divisionCodeApe::Division

Returns the division of this ape code.

Returns:



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

def division
  @division ||= DIVISIONS.find { |e| e.key == classes[0]&.division_key }
end

#sectionCodeApe::Section

Returns the section of this ape code.

Returns:



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

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

#subsectionCodeApe::Subsection

Returns the subsection of this ape code.

Returns:



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

def subsection
  @subsection ||= SUBSECTIONS.find { |e| e.key == classes[0]&.subsection_key }
end

#to_hHash

Returns the hash representation of group label.

Returns:

  • (Hash)

    the hash representation of group label



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

def to_h
  {label: @label}
end