Class: Hedbergism::Quote
- Inherits:
-
Object
- Object
- Hedbergism::Quote
- Defined in:
- lib/hedbergism/quote.rb
Instance Attribute Summary collapse
-
#chunk ⇒ Object
readonly
Returns the value of attribute chunk.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#length_of_chunk ⇒ Object
readonly
Returns the value of attribute length_of_chunk.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#quote ⇒ Object
readonly
Returns the value of attribute quote.
Instance Method Summary collapse
- #blank_line ⇒ Object
- #chunks(length = 75, char = ' ') ⇒ Object
-
#initialize(line) ⇒ Quote
constructor
A new instance of Quote.
- #output_quote_identifiers(text) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(line) ⇒ Quote
Returns a new instance of Quote.
6 7 8 9 10 |
# File 'lib/hedbergism/quote.rb', line 6 def initialize(line) @quote, @location, @date = line.split('~~') @chunk = [] @length_of_chunk = 75 end |
Instance Attribute Details
#chunk ⇒ Object (readonly)
Returns the value of attribute chunk.
4 5 6 |
# File 'lib/hedbergism/quote.rb', line 4 def chunk @chunk end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/hedbergism/quote.rb', line 4 def date @date end |
#length_of_chunk ⇒ Object (readonly)
Returns the value of attribute length_of_chunk.
4 5 6 |
# File 'lib/hedbergism/quote.rb', line 4 def length_of_chunk @length_of_chunk end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
4 5 6 |
# File 'lib/hedbergism/quote.rb', line 4 def location @location end |
#quote ⇒ Object (readonly)
Returns the value of attribute quote.
4 5 6 |
# File 'lib/hedbergism/quote.rb', line 4 def quote @quote end |
Instance Method Details
#blank_line ⇒ Object
32 33 34 |
# File 'lib/hedbergism/quote.rb', line 32 def blank_line "\#" + " " * (@length_of_chunk + 3) + "\#\n" end |
#chunks(length = 75, char = ' ') ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hedbergism/quote.rb', line 40 def chunks(length=75, char=' ') workingline = '' @length_of_chunk = length quote.split(char).each do |word| if workingline.length + word.length + char.length <= length workingline += word + char else @chunk.push(workingline[0..-2]) workingline = word + char end end @chunk.push(workingline[0..-2]) end |
#output_quote_identifiers(text) ⇒ Object
36 37 38 |
# File 'lib/hedbergism/quote.rb', line 36 def output_quote_identifiers(text) "\#" + text.rjust(@length_of_chunk + 2) + " \#\n" end |
#to_s ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hedbergism/quote.rb', line 12 def to_s chunks output = "\#" * (@length_of_chunk + 5) + "\n" output += blank_line @chunk.each do |a| newline = "\# " + a newline = newline.ljust(@length_of_chunk + 5) newline[-1] = "\#" output += "#{newline}\n" end output += blank_line + output_quote_identifiers(@location) if @location output += output_quote_identifiers(@date) if @date output += blank_line output += "\#" * (@length_of_chunk + 5) + "\n" @quote ? output : "" end |