Class: Tracinho::ComplementBuilder

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

Overview

ComplementBuilder converts words with dash in the version without it and vice-versa.

Instance Method Summary collapse

Constructor Details

#initialize(word) ⇒ ComplementBuilder

Returns a new instance of ComplementBuilder.



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

def initialize(word)
  @word = word
end

Instance Method Details

#buildObject

Builds the complementary word.

ComplementBuilder.new(Word.new('fizeste')).build
# => #<Tracinho::Word:0x007f8a9b0ba928 @text="fize-te">

ComplementBuilder.new(Word.new('passa-mos')).build
# => #<Tracinho::Word:0x007f8a9b10f270 @text="passamos">


17
18
19
20
21
# File 'lib/tracinho/complement_builder.rb', line 17

def build
  text = @word.hyphenated? ? remove_dash(@word.to_s) : add_dash(@word.to_s)

  Word.new(text)
end