Class: StyleGuide::Section

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, path) ⇒ Section



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

def initialize(id, path)
  @id = id
  @path = path
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/style_guide/section.rb', line 5

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/style_guide/section.rb', line 5

def path
  @path
end

Class Method Details

.from_paths(paths) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/style_guide/section.rb', line 11

def self.from_paths(paths)
  [*paths].reduce({}) do |sections, path|
    id = id_from_path(path)
    section = sections[id] ||= []
    section << new("#{id}#{section.empty? ? '' : section.count}", path)
    sections
  end.values.flatten
end

.id_from_path(path) ⇒ Object



7
8
9
# File 'lib/style_guide/section.rb', line 7

def self.id_from_path(path)
  File.basename(path).downcase.gsub(/[^a-zA-Z0-9]/, " ").strip.gsub(/\s+/, "_")
end

Instance Method Details

#partialsObject



29
30
31
# File 'lib/style_guide/section.rb', line 29

def partials
  partial_paths.map { |path| StyleGuide::Partial.new(path, self) }.sort_by { |p| p.title }
end

#titleObject



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

def title
  @title ||= File.basename(path).titleize
end