Class: Bunto::Tags::PostComparer
- Inherits:
-
Object
- Object
- Bunto::Tags::PostComparer
- Defined in:
- lib/bunto/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
- #deprecated_equality(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.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bunto/tags/post_url.rb', line 8 def initialize(name) @name = name all, @path, @date, @slug = *name.sub(%r!^/!, "").match(MATCHER) unless all raise Bunto::Errors::InvalidPostNameError, "'#{name}' does not contain valid date and/or title." end @name_regex = %r!^#{path}#{date}-#{slug}\.[^.]+! end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
6 7 8 |
# File 'lib/bunto/tags/post_url.rb', line 6 def date @date end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/bunto/tags/post_url.rb', line 6 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/bunto/tags/post_url.rb', line 6 def path @path end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
6 7 8 |
# File 'lib/bunto/tags/post_url.rb', line 6 def slug @slug end |
Instance Method Details
#==(other) ⇒ Object
25 26 27 |
# File 'lib/bunto/tags/post_url.rb', line 25 def ==(other) other.basename.match(@name_regex) end |
#deprecated_equality(other) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/bunto/tags/post_url.rb', line 29 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
20 21 22 23 |
# File 'lib/bunto/tags/post_url.rb', line 20 def post_date @post_date ||= Utils.parse_date(date, "\"#{date}\" does not contain valid date and/or title.") end |