Class: ThirdPerson
- Inherits:
-
Object
- Object
- ThirdPerson
- Defined in:
- lib/story_time/third_person.rb
Instance Method Summary collapse
- #find(str) ⇒ Object
- #gender_pronouns ⇒ Object
-
#initialize(name = "John Doe", gender = "male") ⇒ ThirdPerson
constructor
A new instance of ThirdPerson.
- #pronoun_conversion(pronoun) ⇒ Object
- #replace(text, replacements = {}) ⇒ Object
Constructor Details
#initialize(name = "John Doe", gender = "male") ⇒ ThirdPerson
Returns a new instance of ThirdPerson.
3 4 5 6 7 8 |
# File 'lib/story_time/third_person.rb', line 3 def initialize(name = "John Doe", gender = "male") @tgr = ::EngTagger.new @name = name @gender = gender @eyes = 0 end |
Instance Method Details
#find(str) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/story_time/third_person.rb', line 10 def find(str) tagged = @tgr.(str) pronouns = @tgr.get_pronouns(tagged).keys {}.tap do |hs| pronouns.each do |pronoun| hs[pronoun] = pronoun_conversion(pronoun) end end end |
#gender_pronouns ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/story_time/third_person.rb', line 43 def gender_pronouns() { "male" => { "my" => "his", "me" => "him", "I" => "he" }, "female" => { "my" => "her", "me" => "her", "I" => "she" } }[@gender] end |
#pronoun_conversion(pronoun) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/story_time/third_person.rb', line 60 def pronoun_conversion(pronoun) { "I" => @name, "my" => gender_pronouns["my"], "me" => gender_pronouns["me"] }[pronoun] || pronoun end |
#replace(text, replacements = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/story_time/third_person.rb', line 22 def replace(text, replacements = {}) replaced = text.dup replacements.keys.each do |rep| if rep == "I" replaced.gsub!(rep) do |val| @eyes += 1 if @eyes > 1 gender_pronouns["I"] else replacements[rep] end end else replaced.gsub!(rep, replacements[rep]) end end replaced end |