Class: Octopress::Printable::PostLinkComparer

Inherits:
Object
  • Object
show all
Defined in:
lib/octopress-printable/tags.rb

Constant Summary collapse

MATCHER =
/^(.+\/)*(\d+-\d+-\d+)-([^\s]*)(\s.*)?$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PostLinkComparer

Returns a new instance of PostLinkComparer.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
# File 'lib/octopress-printable/tags.rb', line 21

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

Instance Attribute Details

#dateObject

Returns the value of attribute date.



19
20
21
# File 'lib/octopress-printable/tags.rb', line 19

def date
  @date
end

#slugObject

Returns the value of attribute slug.



19
20
21
# File 'lib/octopress-printable/tags.rb', line 19

def slug
  @slug
end

#textObject

Returns the value of attribute text.



19
20
21
# File 'lib/octopress-printable/tags.rb', line 19

def text
  @text
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/octopress-printable/tags.rb', line 29

def ==(other)
  slug == post_slug(other)

  # disabled the date check below (used in post_url.rb)
  # otherwise posts with a custom date front-matter will fail if it's different to the slug
  
  #&& date.year  == other.date.year &&
  #date.month == other.date.month &&
  #date.day   == other.date.day
end