Class: Bloggit::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/bloggit/tag.rb

Overview

Tag

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name) ⇒ Tag

Returns a new instance of Tag.



7
8
9
10
11
# File 'lib/bloggit/tag.rb', line 7

def initialize(tag_name)
  @name = tag_name
  @pages = []
  @posts = []
end

Class Attribute Details

.tag_listObject (readonly)

Returns the value of attribute tag_list.



41
42
43
# File 'lib/bloggit/tag.rb', line 41

def tag_list
  @tag_list
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/bloggit/tag.rb', line 5

def name
  @name
end

#pagesObject

Returns the value of attribute pages.



5
6
7
# File 'lib/bloggit/tag.rb', line 5

def pages
  @pages
end

#postsObject

Returns the value of attribute posts.



5
6
7
# File 'lib/bloggit/tag.rb', line 5

def posts
  @posts
end

Class Method Details

.register_page(tag, page) ⇒ Object



47
48
49
50
51
52
# File 'lib/bloggit/tag.rb', line 47

def register_page(tag, page)
  @tag_list ||= {}
  @tag_list[tag] = new(tag) unless @tag_list.has_key? tag
  @tag_list[tag].add_page page
  
end

.register_post(tag, post) ⇒ Object



54
55
56
57
58
# File 'lib/bloggit/tag.rb', line 54

def register_post (tag, post)
  @tag_list ||= {}
  @tag_list[tag] = new(tag) unless @tag_list.has_key? tag
  @tag_list[tag].add_post post
end

.reset!Object



43
44
45
# File 'lib/bloggit/tag.rb', line 43

def reset!
  @tag_list = {}
end

Instance Method Details

#add_page(page) ⇒ Object



29
30
31
32
# File 'lib/bloggit/tag.rb', line 29

def add_page(page)
  @pages << page
  @pages.sort! {|a,b| a.title <=> b.title }.reverse!
end

#add_post(post) ⇒ Object



34
35
36
37
# File 'lib/bloggit/tag.rb', line 34

def add_post(post)
  @posts << post
  @posts.sort! {|a,b| a.publish_date <=> b.publish_date }.reverse!
end

#has_pages?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/bloggit/tag.rb', line 13

def has_pages?
  @pages.length > 0
end

#has_posts?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/bloggit/tag.rb', line 17

def has_posts?
  @posts.length > 0
end


25
26
27
# File 'lib/bloggit/tag.rb', line 25

def permalink
  "tags/#{slug}.html"
end

#slugObject



21
22
23
# File 'lib/bloggit/tag.rb', line 21

def slug
  @name.to_slug
end