Class: Jekyll::Tags::PostComparer

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/tags/post_url.rb

Constant Summary collapse

MATCHER =
/^(.+\/)*(\d+-\d+-\d+)-(.*)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PostComparer

Returns a new instance of PostComparer.

Raises:

  • (ArgumentError)

8
9
10
11
12
13
14
# File 'lib/jekyll/tags/post_url.rb', line 8

def initialize(name)
  @name = name
  all, @path, @date, @slug = *name.sub(/^\//, "").match(MATCHER)
  raise ArgumentError.new("'#{name}' does not contain valid date and/or title.") unless all

  @name_regex = /^#{path}#{date}-#{slug}\.[^.]+/
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date


6
7
8
# File 'lib/jekyll/tags/post_url.rb', line 6

def date
  @date
end

#nameObject (readonly)

Returns the value of attribute name


6
7
8
# File 'lib/jekyll/tags/post_url.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path


6
7
8
# File 'lib/jekyll/tags/post_url.rb', line 6

def path
  @path
end

#slugObject (readonly)

Returns the value of attribute slug


6
7
8
# File 'lib/jekyll/tags/post_url.rb', line 6

def slug
  @slug
end

Instance Method Details

#==(other) ⇒ Object


16
17
18
# File 'lib/jekyll/tags/post_url.rb', line 16

def ==(other)
  other.name.match(@name_regex)
end

#deprecated_equality(other) ⇒ Object


20
21
22
23
24
25
26
# File 'lib/jekyll/tags/post_url.rb', line 20

def deprecated_equality(other)
  date = Utils.parse_date(name, "'#{name}' does not contain valid date and/or title.")
  slug == post_slug(other) &&
    date.year  == other.date.year &&
    date.month == other.date.month &&
    date.day   == other.date.day
end