Class: Rhymera::List

Inherits:
Object
  • Object
show all
Defined in:
lib/rhymera/list.rb

Overview

container for lists of Rhyme and Portmanteau

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function:, word:) ⇒ List

Returns a new instance of List.



14
15
16
17
18
19
20
21
22
23
# File 'lib/rhymera/list.rb', line 14

def initialize(function:, word:)
  @object = Rhymera::RhymeBrain.query(function: function, word: word)
  @query = word
  @type = function
  @entries = []
  build_correct_type

  # add to all array
  self.class.all << self
end

Class Attribute Details

.allObject

Returns the value of attribute all.



11
12
13
# File 'lib/rhymera/list.rb', line 11

def all
  @all
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



5
6
7
# File 'lib/rhymera/list.rb', line 5

def entries
  @entries
end

#objectObject (readonly)

Returns the value of attribute object.



4
5
6
# File 'lib/rhymera/list.rb', line 4

def object
  @object
end

#queryObject (readonly)

Returns the value of attribute query.



4
5
6
# File 'lib/rhymera/list.rb', line 4

def query
  @query
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/rhymera/list.rb', line 4

def type
  @type
end

Instance Method Details

#build_correct_typeObject



25
26
27
28
29
30
31
32
# File 'lib/rhymera/list.rb', line 25

def build_correct_type
  case @type
  when 'getRhymes'
    create_rhymes
  when 'getPortmanteaus'
    create_portmanteaus
  end
end

#create_portmanteausObject



34
35
36
37
38
39
40
# File 'lib/rhymera/list.rb', line 34

def create_portmanteaus
  @object.each do |entry|
    port = Rhymera::Portmanteau.new(source: entry['source'],
                                    combined: entry['combined'])
    entries << port
  end
end

#create_rhymesObject



42
43
44
45
46
47
48
# File 'lib/rhymera/list.rb', line 42

def create_rhymes
  @object.each do |entry|
    rhyme = Rhymera::Rhyme.new(word: entry['word'],
                               syllables: entry['syllables'])
    entries << rhyme
  end
end