Class: Confluence::Bookmark

Inherits:
Page show all
Defined in:
lib/confluence/bookmark.rb

Constant Summary collapse

BOOKMARK_REGEXP =
/\{bookmark.*\}[^\{]*\{bookmark\}/
BOOKMARK_URL_REGEXP =
/\{bookmark:url=([^\}]+)\}/
DESCRIPTION_REGEXP =
/\{bookmark.*\}([^\{]*)\{bookmark\}/

Constants inherited from Page

Page::INVALID_TITLE_CHARS

Instance Attribute Summary collapse

Attributes inherited from Page

#details

Instance Method Summary collapse

Methods inherited from Page

#add_attachment, #attachments, #children, #remove

Methods included from Findable

#find

Methods inherited from Record

client, #client, client=, #labels, #labels=, record_attr_accessor, #record_id

Constructor Details

#initialize(hash) ⇒ Bookmark

Returns a new instance of Bookmark.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/confluence/bookmark.rb', line 9

def initialize(hash)
  # set and delete bookmark_url and description coming from hash
  @bookmark_url = hash.delete :bookmark_url
  @description = hash.delete :description

  # initialize page
  super(hash)

  if content
    # if no bookmark_url from hash, initialize from content
    unless @bookmark_url
      @bookmark_url = content[BOOKMARK_URL_REGEXP, 1]
      @description = content[DESCRIPTION_REGEXP, 1]
    end

    # remove {bookmark} macro from content
    content.gsub!(BOOKMARK_REGEXP, "")
  end
end

Instance Attribute Details

#bookmark_urlObject

Returns the value of attribute bookmark_url.



3
4
5
# File 'lib/confluence/bookmark.rb', line 3

def bookmark_url
  @bookmark_url
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/confluence/bookmark.rb', line 3

def description
  @description
end

Instance Method Details

#[](attr) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/confluence/bookmark.rb', line 29

def [](attr)
  case attr
  when :bookmark_url
    @bookmark_url
  when :description
    @description
  else
    super(attr)
  end
end

#[]=(attr, value) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/confluence/bookmark.rb', line 40

def []=(attr, value)
  case attr
  when :bookmark_url
    @bookmark_url = value
  when :description
    @description = value
  else
    super(attr, value)
  end
end

#store(args = {}) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/confluence/bookmark.rb', line 51

def store(args = {})
  # always set .bookmarks as the parent page
  self.parent_id = Page.find(:space => space, :title => Space::BOOKMARKS_PAGE_TITLE).page_id

  # continue with storing the page
  super(args)
end

#to_hashObject



59
60
61
62
63
64
65
66
# File 'lib/confluence/bookmark.rb', line 59

def to_hash
  page_hash = super

  page_hash["content"] << "\n" unless page_hash["content"].empty?
  page_hash["content"] << bookmark_content

  page_hash
end