Class: Bunto::Tags::PostComparer

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PostComparer



8
9
10
11
12
13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



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

def date
  @date
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#slugObject (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



27
28
29
# File 'lib/bunto/tags/post_url.rb', line 27

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

#deprecated_equality(other) ⇒ Object



31
32
33
34
35
36
# File 'lib/bunto/tags/post_url.rb', line 31

def deprecated_equality(other)
  slug == post_slug(other) &&
    .year  == other.date.year &&
    .month == other.date.month &&
    .day   == other.date.day
end

#post_dateObject



22
23
24
25
# File 'lib/bunto/tags/post_url.rb', line 22

def 
  @post_date ||= Utils.parse_date(date,
    "\"#{date}\" does not contain valid date and/or title.")
end