Class: Remedy::Partial
- Inherits:
-
Object
- Object
- Remedy::Partial
- Defined in:
- lib/remedy/partial.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #+(new_lines) ⇒ Object
- #<<(line) ⇒ Object
- #excerpt(lines_range, width_range) ⇒ Object
- #first ⇒ Object
- #height ⇒ Object (also: #length)
-
#initialize(collection = Array.new) ⇒ Partial
constructor
A new instance of Partial.
- #join(seperator) ⇒ Object
- #last ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #width ⇒ Object
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
#lines ⇒ Object
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 |
#first ⇒ Object
22 23 24 |
# File 'lib/remedy/partial.rb', line 22 def first lines.first end |
#height ⇒ Object 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 |
#last ⇒ Object
26 27 28 |
# File 'lib/remedy/partial.rb', line 26 def last lines.last end |
#to_a ⇒ Object
43 44 45 |
# File 'lib/remedy/partial.rb', line 43 def to_a lines end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/remedy/partial.rb', line 47 def to_s lines.join '\n' end |
#width ⇒ Object
35 36 37 |
# File 'lib/remedy/partial.rb', line 35 def width lines.map{|line| line.length }.max end |