Class: CodeApe::Section

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

Overview

Represent section of ape code (A letter assigned to a subdivision grouping not represented in the final ape code)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, label) ⇒ Section

Creates a new CodeApe::Section

Parameters:

  • key (Symbol, String)

    The section key of ape code

  • label (String)

    The section label of ape code



9
10
11
12
# File 'lib/code_ape/section.rb', line 9

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

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/code_ape/section.rb', line 4

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/code_ape/section.rb', line 4

def label
  @label
end

Instance Method Details

#classesArray<CodeApe::Class>

Returns the classes associated with section of this ape code.

Returns:

  • (Array<CodeApe::Class>)

    the classes associated with section of this ape code



15
16
17
# File 'lib/code_ape/section.rb', line 15

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

#divisionsArray<CodeApe::Division>

Returns the divisions associated with section of this ape code.

Returns:

  • (Array<CodeApe::Division>)

    the divisions associated with section of this ape code



25
26
27
# File 'lib/code_ape/section.rb', line 25

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

#groupsArray<CodeApe::Group>

Returns the groups associated with section of this ape code.

Returns:

  • (Array<CodeApe::Group>)

    the groups associated with section of this ape code



20
21
22
# File 'lib/code_ape/section.rb', line 20

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

#subsectionsArray<CodeApe::Subsection>

Returns the subsections associated with section of this ape code.

Returns:



30
31
32
# File 'lib/code_ape/section.rb', line 30

def subsections
  @subsections ||= SUBSECTIONS.select { |e| classes.map(&:subsection_key).include?(e.key) }
end

#to_hHash

Returns the hash representation of section label.

Returns:

  • (Hash)

    the hash representation of section label



35
36
37
# File 'lib/code_ape/section.rb', line 35

def to_h
  {label: @label}
end