class Tracinho::ComplementBuilder

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

Public Class Methods

new(word) click to toggle source
# File lib/tracinho/complement_builder.rb, line 6
def initialize(word)
  @word = word
end

Public Instance Methods

build() click to toggle source

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">
# 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

Private Instance Methods

add_dash(text) click to toggle source
# File lib/tracinho/complement_builder.rb, line 29
def add_dash(text)
  case text
  when /os$/
    text.dup.insert(-4, '-')
  when /sse$/
    text.dup.gsub(/sse/, '-se')
  else
    text.dup.insert(-3, '-')
  end
end
remove_dash(text) click to toggle source
# File lib/tracinho/complement_builder.rb, line 25
def remove_dash(text)
  text.match?(/\-se$/) ? text.dup.tr('-', 's') : text.dup.delete('-')
end