class Bunto::Tags::PostComparer

Constants

MATCHER

Attributes

date[R]
name[R]
path[R]
slug[R]

Public Class Methods

new(name) click to toggle source
# 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

  escaped_slug = Regexp.escape(slug)
  @name_regex = %r!^_posts/#{path}#{date}-#{escaped_slug}\.[^.]+|
    ^#{path}_posts/?#{date}-#{escaped_slug}\.[^.]+!x
end

Public Instance Methods

==(other) click to toggle source
# File lib/bunto/tags/post_url.rb, line 27
def ==(other)
  other.relative_path.match(@name_regex)
end
deprecated_equality(other) click to toggle source
# File lib/bunto/tags/post_url.rb, line 31
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() click to toggle source
# File lib/bunto/tags/post_url.rb, line 22
def post_date
  @post_date ||= Utils.parse_date(date,
    "\"#{date}\" does not contain valid date and/or title.")
end

Private Instance Methods

post_slug(other) click to toggle source

Construct the directory-aware post slug for a Bunto::Post

other - the Bunto::Post

Returns the post slug with the subdirectory (relative to _posts)

# File lib/bunto/tags/post_url.rb, line 44
def post_slug(other)
  path = other.basename.split("/")[0...-1].join("/")
  if path.nil? || path == ""
    other.data["slug"]
  else
    path + "/" + other.data["slug"]
  end
end