Class: Remedy::Partial

Inherits:
Object
  • Object
show all
Defined in:
lib/remedy/partial.rb

Direct Known Subclasses

Content, Footer, Header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection = Array.new) ⇒ Partial

Returns a new instance of Partial.



3
4
5
6
# File 'lib/remedy/partial.rb', line 3

def initialize collection = Array.new
  @lines = Array.new
  self + collection
end

Instance Attribute Details

#linesObject

Returns the value of attribute lines.



7
8
9
# File 'lib/remedy/partial.rb', line 7

def lines
  @lines
end

Instance Method Details

#+(new_lines) ⇒ Object



9
10
11
12
13
# File 'lib/remedy/partial.rb', line 9

def + new_lines
  new_lines.each do |line|
    self << line
  end
end

#<<(line) ⇒ Object



15
16
17
18
# File 'lib/remedy/partial.rb', line 15

def << line
  reset_width!
  @lines += clean line unless line.nil? || line.empty?
end

#excerpt(lines_range, width_range) ⇒ Object



52
53
54
# File 'lib/remedy/partial.rb', line 52

def excerpt lines_range, width_range
  self.class.new lines[lines_range].map { |line| line[width_range] }
end

#firstObject



20
21
22
# File 'lib/remedy/partial.rb', line 20

def first
  lines.first
end

#join(seperator) ⇒ Object



48
49
50
# File 'lib/remedy/partial.rb', line 48

def join seperator
  lines.join seperator
end

#lastObject



24
25
26
# File 'lib/remedy/partial.rb', line 24

def last
  lines.last
end

#lengthObject



28
29
30
# File 'lib/remedy/partial.rb', line 28

def length
  lines.length
end

#sizeObject



36
37
38
# File 'lib/remedy/partial.rb', line 36

def size
  Size.new length, width
end

#to_aObject



40
41
42
# File 'lib/remedy/partial.rb', line 40

def to_a
  lines
end

#to_sObject



44
45
46
# File 'lib/remedy/partial.rb', line 44

def to_s
  lines.join '\n'
end

#widthObject



32
33
34
# File 'lib/remedy/partial.rb', line 32

def width
  @width ||= lines.max{|line| line.length }.length
end