Class: ViewSpec::Subject

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/view_spec/subject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Subject

Returns a new instance of Subject.



9
10
11
# File 'lib/view_spec/subject.rb', line 9

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/view_spec/subject.rb', line 7

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/view_spec/subject.rb', line 25

def <=>(other)
  if other.is_a?(self.class)
    to_identifier.casecmp other.to_identifier
  else
    value <=> other
  end
end

#to_identifierObject



17
18
19
# File 'lib/view_spec/subject.rb', line 17

def to_identifier
  @identifier ||= to_parameterized_path
end

#to_parameterized_pathObject



33
34
35
# File 'lib/view_spec/subject.rb', line 33

def to_parameterized_path
  to_path.parameterize
end

#to_pathObject



37
38
39
40
# File 'lib/view_spec/subject.rb', line 37

def to_path
  path = @value.to_s.underscore.gsub(/\s+/, "_").delete_suffix(".rb")
  path.gsub(/(_component|\/component)$/, "")
end

#to_short_identifierObject



21
22
23
# File 'lib/view_spec/subject.rb', line 21

def to_short_identifier
  @short_identifier ||= to_identifier.split("/").last
end

#to_titleObject



13
14
15
# File 'lib/view_spec/subject.rb', line 13

def to_title
  @title ||= to_short_identifier.titleize
end