Class: Mutiny::Subjects::SubjectSet
- Inherits:
-
Object
- Object
- Mutiny::Subjects::SubjectSet
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/mutiny/subjects/subject_set.rb
Instance Attribute Summary collapse
-
#subjects ⇒ Object
readonly
Returns the value of attribute subjects.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(subjects) ⇒ SubjectSet
constructor
A new instance of SubjectSet.
- #names ⇒ Object
-
#per_file ⇒ Object
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.
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
#subjects ⇒ Object (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: ==
28 29 30 |
# File 'lib/mutiny/subjects/subject_set.rb', line 28 def eql?(other) is_a?(other.class) && other.subjects == subjects end |
#names ⇒ Object
13 14 15 |
# File 'lib/mutiny/subjects/subject_set.rb', line 13 def names @names ||= map(&:name).sort end |
#per_file ⇒ Object
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 |