Class: RandomWords::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/random-words/source.rb

Overview

A class representing a source of words for the RandomWords library.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path) ⇒ Source

Initializes a new Source instance.

Parameters:

  • name (Symbol)

    The name of the source

  • path (String)

    The path to the source directory



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/random-words/source.rb', line 12

def initialize(name, path)
  @name = name.to_sym
  @path = path
  config = IO.read(File.join(path, 'config.yml'))
  @config = YAML.safe_load(config, aliases: true)
  @names = @config['triggers'] || [name]
  @description = @config['description'] || 'No description available'
  @dictionary = from_files
  @dictionary[:all_words] = @dictionary.values.flatten.uniq
  @dictionary[:terminators], @dictionary[:extended_punctuation] = from_file('terminators').split_terminators
  @dictionary[:first_names], @dictionary[:last_names], @dictionary[:full_names] = from_file('names').split_names
rescue StandardError
  @name = name.to_sym
  @config = {}
  @names = [name]
  @description = 'No description available'
  @dictionary = from_files
  @dictionary[:all_words] = @dictionary.values.flatten.uniq
  @dictionary[:terminators], @dictionary[:extended_punctuation] = from_file('terminators').split_terminators
  @dictionary[:first_names], @dictionary[:last_names], @dictionary[:full_names] = from_file('names').split_names
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/random-words/source.rb', line 7

def config
  @config
end

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/random-words/source.rb', line 7

def description
  @description
end

#dictionaryObject (readonly)

Returns the value of attribute dictionary.



7
8
9
# File 'lib/random-words/source.rb', line 7

def dictionary
  @dictionary
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/random-words/source.rb', line 7

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names.



7
8
9
# File 'lib/random-words/source.rb', line 7

def names
  @names
end