Class: Quotify::Quote

Inherits:
Object
  • Object
show all
Defined in:
lib/quotify/quote.rb

Overview

This class represents a quote object

Instance Method Summary collapse

Constructor Details

#initialize(quote: nil, author: nil) ⇒ Quote

Generates a quote

Parameters:

  • quote (#to_s) (defaults to: nil)

    A specified quote

  • author (#to_s) (defaults to: nil)

    A specified author



14
15
16
17
# File 'lib/quotify/quote.rb', line 14

def initialize(quote: nil, author: nil)
  @quote = quote || Quotify.config[:quotes].sample
  @author = author || Quotify.config[:authors].sample
end

Instance Method Details

#author#to_s

Returns the author

Returns:



46
47
48
# File 'lib/quotify/quote.rb', line 46

def author
  @author
end

#quote#to_s

Returns the quote

Returns:



52
53
54
# File 'lib/quotify/quote.rb', line 52

def quote
  @quote
end

#to_hashHash Also known as: to_h

Returns the quote and author in a hash

Returns:

  • (Hash)


34
35
36
# File 'lib/quotify/quote.rb', line 34

def to_hash
  { quote: @quote, author: @author }
end

#to_jsonString

Returns the quote and author in a JSON structured String

Returns:

  • (String)


40
41
42
# File 'lib/quotify/quote.rb', line 40

def to_json
  to_hash.to_json
end

#to_s(spacer: Quotify.config[:default_spacer]) ⇒ Object

Returns the quote and author in a string format

Parameters:

  • spacer (Hash) (defaults to: Quotify.config[:default_spacer])

    a customizable set of options

Options Hash (spacer:):

  • Characters (#to_s)

    between quote and author



21
22
23
# File 'lib/quotify/quote.rb', line 21

def to_s(spacer: Quotify.config[:default_spacer])
  "#{@quote}#{spacer}#{@author}"
end

#to_str(spacer: Quotify.config[:default_spacer]) ⇒ Object

Returns the quote and author in a string format

Parameters:

  • spacer (Hash) (defaults to: Quotify.config[:default_spacer])

    a customizable set of options

Options Hash (spacer:):

  • Characters (#to_s)

    between quote and author



28
29
30
# File 'lib/quotify/quote.rb', line 28

def to_str(spacer: Quotify.config[:default_spacer])
  to_s(spacer: spacer)
end