Class: MarkdownRecord::FileSorting::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_record/file_sorting/base.rb

Direct Known Subclasses

DateSorter, SemVerSorter

Instance Method Summary collapse

Constructor Details

#initialize(sort_regex = /^(\d+)_/) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/markdown_record/file_sorting/base.rb', line 5

def initialize(sort_regex = /^(\d+)_/)
  @sort_regex = sort_regex
end

Instance Method Details

#path_to_sort_value(path) ⇒ Object



9
10
11
12
# File 'lib/markdown_record/file_sorting/base.rb', line 9

def path_to_sort_value(path)
  m = path.split("/").last.match(@sort_regex)
  to_sort_value(m.try(:[], 1))
end

#remove_prefix(filename_or_id) ⇒ Object



18
19
20
21
22
# File 'lib/markdown_record/file_sorting/base.rb', line 18

def remove_prefix(filename_or_id)
  parts = filename_or_id.split("/")
  parts = parts.map { |p| p.sub(@sort_regex,"")}
  parts.join("/")
end

#to_sort_value(value) ⇒ Object



14
15
16
# File 'lib/markdown_record/file_sorting/base.rb', line 14

def to_sort_value(value)
  value.to_i
end