Module: Nokogiri::Decorators::XBEL::Folder

Includes:
Entry
Defined in:
lib/nokogiri/decorators/xbel/folder.rb

Instance Attribute Summary

Attributes included from Entry

#info

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Entry

#added, #added=, #attributes=, #desc, #desc=, #id, #id=, #initialize_decorator, #title, #title=

Class Method Details

.extended(node) ⇒ Object


5
6
7
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 5

def self.extended(node)
  node.initialize_decorator
end

Instance Method Details

#add_alias(ref) ⇒ Object

Builds an alias with given attributes and add it.


56
57
58
59
60
61
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 56

def add_alias(ref)
  node = Nokogiri::XML::Node.new 'alias', document
  node.ref = (Entry === ref) ? ref.id : ref.to_s

  add_child node
end

#add_bookmark(title, href, attributes = {}, &block) ⇒ Object

Builds a bookmark with given attributes and add it.


46
47
48
49
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 46

def add_bookmark(title, href, attributes = {}, &block)
  attributes = attributes.merge :title => title, :href => href
  add_child build(:bookmark, attributes, &block)
end

#add_folder(title, attributes = {}, &block) ⇒ Object

Builds a folder with given attributes and add it.


51
52
53
54
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 51

def add_folder(title, attributes = {}, &block)
  attributes = attributes.merge :title => title
  add_child build(:folder, attributes, &block)
end

#add_separatorObject

Builds a saperator with given attributes and add it.


63
64
65
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 63

def add_separator
  add_child Nokogiri::XML::Node.new('separator', document)
end

#aliasesObject

Returns an instance of NodeSet with all aliases in this folder.


14
15
16
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 14

def aliases
  xpath './alias'
end

#bookmarksObject

Returns an instance of NodeSet with all bookmarks in this folder.


18
19
20
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 18

def bookmarks
  xpath './bookmark'
end

#build(type, attributes = {}) {|node| ... } ⇒ Object

Yields:

  • (node)

36
37
38
39
40
41
42
43
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 36

def build(type, attributes = {})
  node = Nokogiri::XML::Node.new(type.to_s, document)
  node.attributes = attributes

  yield node if block_given?

  node
end

#entriesObject

Returns an instance of NodeSet with possible children in this folder.


10
11
12
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 10

def entries
  xpath './alias | ./bookmark | ./folder | ./separator'
end

#folder?Boolean

:nodoc:

Returns:

  • (Boolean)

26
27
28
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 26

def folder? #:nodoc:
  true
end

#foldersObject

Returns an instance of NodeSet with all folders in this folder.


22
23
24
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 22

def folders
  xpath './folder'
end

#generate_idObject


67
68
69
70
71
72
73
# File 'lib/nokogiri/decorators/xbel/folder.rb', line 67

def generate_id
  "#{ id }#{ document.div_id_er }" << xpath('./bookmark | ./folder').
      inject(0) { |next_id, child|
          succ_num_id = child.id[/(\d+)$/, 1].to_i.succ
          succ_num_id > next_id ? succ_num_id : next_id
      }.to_s
end