Class: RandomWords::Source
- Inherits:
-
Object
- Object
- RandomWords::Source
- Defined in:
- lib/random-words/source.rb
Overview
A class representing a source of words for the RandomWords library.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#dictionary ⇒ Object
readonly
Returns the value of attribute dictionary.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Instance Method Summary collapse
-
#initialize(name, path) ⇒ Source
constructor
Initializes a new Source instance.
Constructor Details
#initialize(name, path) ⇒ Source
Initializes a new Source instance.
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/random-words/source.rb', line 7 def config @config end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/random-words/source.rb', line 7 def description @description end |
#dictionary ⇒ Object (readonly)
Returns the value of attribute dictionary.
7 8 9 |
# File 'lib/random-words/source.rb', line 7 def dictionary @dictionary end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/random-words/source.rb', line 7 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
7 8 9 |
# File 'lib/random-words/source.rb', line 7 def names @names end |