Class: Spoonerize::Config

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

Overview

Runtime options used by the CLI and Spoonerism instances.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpoonerize::Config

Create instance of Config.



48
49
50
51
52
53
54
55
56
57
# File 'lib/spoonerize/config.rb', line 48

def initialize
  @lazy = false
  @lazy_words = %w[i a an and in of the my your his her him hers to is]
  @excluded_words = []
  @consonants_only = false
  @reverse = false
  @logfile_name = File.expand_path(
    File.join(ENV["HOME"], ".cache", "spoonerize", "spoonerize.csv")
  )
end

Instance Attribute Details

#consonants_onlyBoolean

When true, only consonant-starting words are eligible to be flipped.

Returns:

  • (Boolean)


29
30
31
# File 'lib/spoonerize/config.rb', line 29

def consonants_only
  @consonants_only
end

#excluded_wordsArray

Words that should not be altered.

Returns:

  • (Array)


23
24
25
# File 'lib/spoonerize/config.rb', line 23

def excluded_words
  @excluded_words
end

#lazyBoolean

Lazy mode. If true, words in lazy_words will not be altered.

Returns:

  • (Boolean)


11
12
13
# File 'lib/spoonerize/config.rb', line 11

def lazy
  @lazy
end

#lazy_wordsArray

Words to skip when lazy is true.

Returns:

  • (Array)


17
18
19
# File 'lib/spoonerize/config.rb', line 17

def lazy_words
  @lazy_words
end

#logfile_nameString

Name of the log file. Should be a fully-qualified file path.

Returns:

  • (String)


42
43
44
# File 'lib/spoonerize/config.rb', line 42

def logfile_name
  @logfile_name
end

#reverseBoolean

When true, reverse the order of the flipping. Only makes a difference when there are more than two flip-able words.

Returns:

  • (Boolean)


36
37
38
# File 'lib/spoonerize/config.rb', line 36

def reverse
  @reverse
end

Instance Method Details

#with(**overrides) ⇒ Spoonerize::Config

Create a copy of the current config with optional overrides.

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/spoonerize/config.rb', line 63

def with(**overrides)
  self.class.new.tap do |config|
    config.lazy = lazy
    config.lazy_words = lazy_words.dup
    config.excluded_words = excluded_words.dup
    config.consonants_only = consonants_only
    config.reverse = reverse
    config.logfile_name = logfile_name

    overrides.each do |key, value|
      config.public_send(:"#{key}=", copy_value(value))
    end
  end
end