Class: Jekyll::Tags::PostComparer
- Inherits:
-
Object
- Object
- Jekyll::Tags::PostComparer
- Defined in:
- lib/jekyll/tags/post_url.rb
Constant Summary collapse
- MATCHER =
Deprecated (soft; No interpreter warnings). To be removed in v5.0. Use private constant ‘POST_PATH_MATCHER` instead.
%r!^(.+/)*(\d+-\d+-\d+)-(.*)$!.freeze
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns ‘MatchData` or `nil`.
-
#deprecated_equality(other) ⇒ Object
Deprecated.
-
#initialize(name) ⇒ PostComparer
constructor
A new instance of PostComparer.
- #post_date ⇒ Object
Constructor Details
#initialize(name) ⇒ PostComparer
Returns a new instance of PostComparer.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jekyll/tags/post_url.rb', line 16 def initialize(name) @name = name all, @path, @date, @slug = *name.delete_prefix("/").match(POST_PATH_MATCHER) unless all raise Jekyll::Errors::InvalidPostNameError, "'#{name}' does not contain valid date and/or title." end basename_pattern = "#{date}-#{Regexp.escape(slug)}\\.[^.]+" @name_regex = %r!\A_posts/#{path}#{basename_pattern}|\A#{path}_posts/?#{basename_pattern}! end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
14 15 16 |
# File 'lib/jekyll/tags/post_url.rb', line 14 def date @date end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/jekyll/tags/post_url.rb', line 14 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/jekyll/tags/post_url.rb', line 14 def path @path end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
14 15 16 |
# File 'lib/jekyll/tags/post_url.rb', line 14 def slug @slug end |
Instance Method Details
#==(other) ⇒ Object
Returns ‘MatchData` or `nil`.
34 35 36 |
# File 'lib/jekyll/tags/post_url.rb', line 34 def ==(other) other.relative_path.match(@name_regex) end |
#deprecated_equality(other) ⇒ Object
Deprecated. To be removed in v5.0.
39 40 41 42 43 44 |
# File 'lib/jekyll/tags/post_url.rb', line 39 def deprecated_equality(other) slug == post_slug(other) && post_date.year == other.date.year && post_date.month == other.date.month && post_date.day == other.date.day end |
#post_date ⇒ Object
29 30 31 |
# File 'lib/jekyll/tags/post_url.rb', line 29 def post_date @post_date ||= Utils.parse_date(date, "Path '#{name}' does not contain valid date.") end |