Class: Remedy::Partial

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

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
19
20
# File 'lib/remedy/partial.rb', line 15

def << line
  reset_width!
  line = "#{line}" # opportunistically convert any object into a string
  @lines += clean line unless line.nil? || line.empty?
  self
end

#excerpt(lines_range, width_range) ⇒ Object



55
56
57
# File 'lib/remedy/partial.rb', line 55

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

#firstObject



22
23
24
# File 'lib/remedy/partial.rb', line 22

def first
  lines.first
end

#heightObject Also known as: length



30
31
32
# File 'lib/remedy/partial.rb', line 30

def height
  lines.length
end

#join(seperator) ⇒ Object



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

def join seperator
  lines.join seperator
end

#lastObject



26
27
28
# File 'lib/remedy/partial.rb', line 26

def last
  lines.last
end

#sizeObject



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

def size
  Size.new height, width
end

#to_aObject



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

def to_a
  lines
end

#to_sObject



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

def to_s
  lines.join '\n'
end

#widthObject



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

def width
  lines.map{|line| line.length }.max
end