Class: Bridgetown::Tags::PostComparer
- Inherits:
-
Object
- Object
- Bridgetown::Tags::PostComparer
- Defined in:
- bridgetown-core/lib/bridgetown-core/tags/post_url.rb
Constant Summary collapse
- MATCHER =
%r!^(.+/)*(\d+-\d+-\d+)-(.*)$!
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
-
#initialize(name) ⇒ PostComparer
constructor
A new instance of PostComparer.
-
#post_date ⇒ Object
Constructor Details
#initialize(name) ⇒ PostComparer
Returns a new instance of PostComparer.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 10 def initialize(name) @name = name all, @path, @date, @slug = *name.sub(%r!^/!, "").match(MATCHER) unless all raise Bridgetown::Errors::FatalException, "'#{name}' does not contain valid date and/or title." end escaped_slug = Regexp.escape(slug) @name_regex = %r!^_posts/#{path}#{date}-#{escaped_slug}\.[^.]+| ^#{path}_posts/?#{date}-#{escaped_slug}\.[^.]+!x end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
8 9 10 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 8 def date @date end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 8 def path @path end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
8 9 10 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 8 def slug @slug end |
Instance Method Details
#==(other) ⇒ Object
31 32 33 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 31 def ==(other) other.relative_path.to_s.match(@name_regex) end |
#post_date ⇒ Object
24 25 26 27 28 29 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 24 def post_date @post_date ||= Utils.parse_date( date, "'#{date}' does not contain valid date and/or title." ) end |