Class: Mutiny::Subjects::SubjectSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/mutiny/subjects/subject_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subjects) ⇒ SubjectSet

Returns a new instance of SubjectSet.



9
10
11
# File 'lib/mutiny/subjects/subject_set.rb', line 9

def initialize(subjects)
  @subjects = subjects
end

Instance Attribute Details

#subjectsObject (readonly)

Returns the value of attribute subjects.



6
7
8
# File 'lib/mutiny/subjects/subject_set.rb', line 6

def subjects
  @subjects
end

Instance Method Details

#[](index) ⇒ Object



17
18
19
# File 'lib/mutiny/subjects/subject_set.rb', line 17

def [](index)
  subjects.detect { |s| s.name == index }
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


28
29
30
# File 'lib/mutiny/subjects/subject_set.rb', line 28

def eql?(other)
  is_a?(other.class) && other.subjects == subjects
end

#namesObject



13
14
15
# File 'lib/mutiny/subjects/subject_set.rb', line 13

def names
  @names ||= map(&:name).sort
end

#per_fileObject

Returns a new SubjectSet which contains only one subject per source file For source files that contain more than one subject (i.e., Ruby module), the subjects are ordered by name alphabetically and only the first is used



24
25
26
# File 'lib/mutiny/subjects/subject_set.rb', line 24

def per_file
  self.class.new(group_by(&:path).values.map { |subjects| subjects.sort_by(&:name).first })
end