Class: MarkdownRecord::FileSorting::Base
- Inherits:
-
Object
- Object
- MarkdownRecord::FileSorting::Base
- Defined in:
- lib/markdown_record/file_sorting/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(sort_regex = /^(\d+)_/) ⇒ Base
constructor
A new instance of Base.
- #path_to_sort_value(path) ⇒ Object
- #remove_prefix(filename_or_id) ⇒ Object
- #to_sort_value(value) ⇒ Object
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 |