Class: PersonalFaker::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(choose_text) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
# File 'lib/personal_faker.rb', line 9

def initialize(choose_text)
  if choose_text == 'dr-seuss'
    @file = 'lib/personal_faker/texts/dr-seuss.rtf'
  elsif choose_text == 'pride-and-prejudice'
    @file = 'lib/personal_faker/texts/pride-and-prejudice.rtf'
  elsif choose_text == 'macbeth'
    @file = 'lib/personal_faker/texts/macbeth.rtf'
  end
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/personal_faker.rb', line 7

def file
  @file
end

#tableObject

Returns the value of attribute table.



5
6
7
# File 'lib/personal_faker.rb', line 5

def table
  @table
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/personal_faker.rb', line 6

def text
  @text
end

Instance Method Details

#questionObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/personal_faker.rb', line 62

def question
  word = table.keys.sample.capitalize
  sentence = word
  10.times do
    if table[word]
      word = table[word].sample
    else
      word = table.keys.sample
    end
    sentence = sentence + " " + word
  end
  sentence = sentence + "?"
end

#sentenceObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/personal_faker.rb', line 48

def sentence
  word = table.keys.sample.capitalize
  sentence = word
  10.times do
    if table[word]
      word = table[word].sample
    else
      word = table.keys.sample
    end
    sentence = sentence + " " + word
  end
  sentence = sentence + "."
end

#text_phrase(count) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/personal_faker.rb', line 80

def text_phrase(count)
  phrase = sentence
  (count - 1).times do
    phrase << " " + sentence
  end
  phrase
end

#wordObject



76
77
78
# File 'lib/personal_faker.rb', line 76

def word
  word = table.keys.sample
end