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
-
#initialize(collection = Array.new) ⇒ Partial
constructor
A new instance of Partial.
- #join(seperator) ⇒ Object
- #last ⇒ Object
- #length ⇒ 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 |
# 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 |
#first ⇒ Object
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 |
#last ⇒ Object
24 25 26 |
# File 'lib/remedy/partial.rb', line 24 def last lines.last end |
#length ⇒ Object
28 29 30 |
# File 'lib/remedy/partial.rb', line 28 def length lines.length end |
#to_a ⇒ Object
40 41 42 |
# File 'lib/remedy/partial.rb', line 40 def to_a lines end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/remedy/partial.rb', line 44 def to_s lines.join '\n' end |
#width ⇒ Object
32 33 34 |
# File 'lib/remedy/partial.rb', line 32 def width @width ||= lines.max{|line| line.length }.length end |