Class: Diakonos::Clipboard

Inherits:
Object show all
Defined in:
lib/diakonos/clipboard.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_clips) ⇒ Clipboard

Returns a new instance of Clipboard.



4
5
6
7
# File 'lib/diakonos/clipboard.rb', line 4

def initialize( max_clips )
  @clips = Array.new
  @max_clips = max_clips
end

Instance Method Details

#[](arg) ⇒ Object



9
10
11
# File 'lib/diakonos/clipboard.rb', line 9

def [] ( arg )
  @clips[ arg ]
end

#add_clip(text) ⇒ Object

text is an array of Strings Returns true iff a clip was added, and only non-nil text can be added.



20
21
22
23
24
25
# File 'lib/diakonos/clipboard.rb', line 20

def add_clip( text )
  return false if text.nil?
  @clips.unshift text
  @clips.pop if @clips.length > @max_clips
  true
end

#append_to_clip(text) ⇒ Object

text is an array of Strings (lines) Appends the lines to the current clip. If no current clip, then a new clip is created. Returns true iff the text was successfully appended.



37
38
39
40
41
42
43
44
# File 'lib/diakonos/clipboard.rb', line 37

def append_to_clip( text )
  return false if text.nil?
  return add_clip( text ) if @clips.length == 0
  last_clip = @clips[ 0 ]
  last_clip.pop if last_clip[ -1 ] == ""
  @clips[ 0 ] = last_clip + text
  true
end

#clipObject



13
14
15
# File 'lib/diakonos/clipboard.rb', line 13

def clip
  @clips[ 0 ]
end

#eachObject



27
28
29
30
31
# File 'lib/diakonos/clipboard.rb', line 27

def each
  @clips.each do |clip|
    yield clip
  end
end