Module: Owoify

Defined in:
lib/owoify_rb.rb

Overview

Owoify module is the main module where owoify function lies in. Since owoify is literally just a function, users are expected to invoke owoify by calling Owoify.owoify().

Class Method Summary collapse

Class Method Details

.owoify(source, level = :owo) ⇒ String

The main entry point of the owoify function. Pass in the source string and the desired owoify level.

Parameters:

  • source (String)

    The source string to owoify.

  • level (Symbol) (defaults to: :owo)

    The desired owoness level of the result string.

Returns:

  • (String)

    The owoified string according to the specified owoness level.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/owoify_rb.rb', line 15

def self.owoify(source, level = :owo)
  word_matches = source.scan(/[^\s]+/).flatten
  space_matches = source.scan(/\s+/).flatten
  words = word_matches.map { |x| Word.new(x) }
  spaces = space_matches.map { |x| Word.new(x) }
  words.map! do |w|
    SPECIFIC_WORD_MAPPING_LIST.each do |f|
      w = f.call(w)
    end
    case level
    when :owo
      OWO_MAPPING_LIST.each do |f|
        w = f.call(w)
      end
    when :uwu
      UWU_MAPPING_LIST.each do |f|
        w = f.call(w)
      end
      OWO_MAPPING_LIST.each do |f|
        w = f.call(w)
      end
    when :uvu
      UVU_MAPPING_LIST.each do |f|
        w = f.call(w)
      end
      UWU_MAPPING_LIST.each do |f|
        w = f.call(w)
      end
      OWO_MAPPING_LIST.each do |f|
        w = f.call(w)
      end
    else
      raise ArgumentError, 'The specified owoify level is not supported.'
    end
    w
  end

  result = interleave_arrays(words, spaces)
  result_strings = result.map(&:to_s)
  result_strings.join
end

.uvuify(source) ⇒ String

Owoify the source string using :uvu owoness.

Parameters:

  • source (String)

    The source string to owoify

Returns:

  • (String)

    The owoified string using :uvu owoness level.



67
68
69
# File 'lib/owoify_rb.rb', line 67

def self.uvuify(source)
  self.owoify(source, :uvu)
end

.uwuify(source) ⇒ String

Owoify the source string using :uwu owoness.

Parameters:

  • source (String)

    The source string to owoify

Returns:

  • (String)

    The owoified string using :uwu owoness level.



60
61
62
# File 'lib/owoify_rb.rb', line 60

def self.uwuify(source)
  self.owoify(source, :uwu)
end