Class: VER::Bookmarks

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ver/methods/bookmark.rb

Overview

Methods

Defined Under Namespace

Classes: Bookmark

Instance Method Summary collapse

Constructor Details

#initializeBookmarks

Returns a new instance of Bookmarks.



111
112
113
114
# File 'lib/ver/methods/bookmark.rb', line 111

def initialize
  @bm = []
  @idx = nil
end

Instance Method Details

#<<(value) ⇒ Object



147
148
149
150
# File 'lib/ver/methods/bookmark.rb', line 147

def <<(value)
  add_unnamed(value)
  self
end

#[](name) ⇒ Object



152
153
154
# File 'lib/ver/methods/bookmark.rb', line 152

def [](name)
  @bm.find{|bm| bm.name == name }
end

#add_named(name, value) ⇒ Object Also known as: []=



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ver/methods/bookmark.rb', line 120

def add_named(name, value)
  if value.is_a?(Bookmark)
    bm = value.dup
  else
    bm = Bookmark.new(name, *value.to_a)
  end

  @bm << bm
  @bm.uniq!
  @bm.sort!
  bm
end

#add_unnamed(value) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ver/methods/bookmark.rb', line 134

def add_unnamed(value)
  if value.is_a?(Bookmark)
    bm = value
  else
    bm = Bookmark.new(nil, *value.to_a)
  end

  @bm << bm
  @bm.uniq!
  @bm.sort!
  bm
end

#at(pos) ⇒ Object



176
177
178
179
# File 'lib/ver/methods/bookmark.rb', line 176

def at(pos)
  needle = Bookmark.new(nil, *pos)
  @bm.find{|bm| needle == bm }
end

#delete(name) ⇒ Object



160
161
162
163
164
# File 'lib/ver/methods/bookmark.rb', line 160

def delete(name)
  if found = @bm.find{|bm| bm.name == name }
    @bm.delete(found)
  end
end

#each(&block) ⇒ Object



116
117
118
# File 'lib/ver/methods/bookmark.rb', line 116

def each(&block)
  @bm.each(&block)
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/ver/methods/bookmark.rb', line 156

def key?(name)
  @bm.any?{|bm| bm.name == name }
end

#next_from(pos) ⇒ Object



166
167
168
169
# File 'lib/ver/methods/bookmark.rb', line 166

def next_from(pos)
  needle = Bookmark.new(nil, *pos)
  @bm.find{|bm| bm > needle }
end

#prev_from(pos) ⇒ Object



171
172
173
174
# File 'lib/ver/methods/bookmark.rb', line 171

def prev_from(pos)
  needle = Bookmark.new(nil, *pos)
  @bm.reverse.find{|bm| needle > bm }
end