Class: ProgrammingIpsum::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/programming_ipsum/base.rb

Direct Known Subclasses

AdviceIpsum

Instance Method Summary collapse

Constructor Details

#initialize(phrases, context) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/programming_ipsum/base.rb', line 6

def initialize(phrases, context)
  @phrases = phrases
  @render_context = RenderContext.new(context)
end

Instance Method Details

#all_phrasesObject

For debugging purposes only - not optimized for general use



18
19
20
21
22
23
24
25
26
27
# File 'lib/programming_ipsum/base.rb', line 18

def all_phrases
  width = @phrases.length.to_s.length

  # twice as fast as string concat!
  input = @phrases.each_with_index.map do |phrase, i|
    i.to_s.rjust(width) + ": " + phrase
  end.join("\n")

  render(input)
end

#sequence(count = 3) ⇒ Object

Render a sequence of phrases for this ipsum Does not guarantee a number of sentences, just phrases.



13
14
15
# File 'lib/programming_ipsum/base.rb', line 13

def sequence(count = 3)
  render @phrases.sample(count).join(" ")
end