module Quotes

Constants

MAJOR
MINOR
PATCH
VERSION

Public Class Methods

all() click to toggle source
# File lib/cryptoquotes.rb, line 50
def self.all
  @all ||= begin
              all = []
              sources.each { |source| all += read_builtin( source ) }
              all
           end
  @all
end
banner() click to toggle source
lottery() click to toggle source
# File lib/cryptoquotes.rb, line 62
def self.lottery
  ## get random shuffle (shuffle three times - why? why not?)
  @lottery ||= (0..(all.size-1)).to_a.shuffle.shuffle.shuffle
end
random() click to toggle source
# File lib/cryptoquotes.rb, line 67
def self.random    ## get a random quote
  idx = lottery.shift   ## remove (shift) first index (ticket) in queue / array
  ## puts "[debug] rand => #{idx} of #{all.size} (remaining #{lottery.size})"
  all[ idx ]
end
read( path ) click to toggle source
# File lib/cryptoquotes.rb, line 22
def self.read( path )  ## read-in a quote dataset - returns an array of hash records
  ## puts "[debug] reading #{path}..."
  txt = File.open( path, 'r:utf-8' ) { |f| f.read }
  data = YAML.load( txt )

  ## auto-fill by-line using filename (convention)
  ##  e.g.    David_Gerard.yml  => David Gerard
  by_line = File.basename( path, File.extname( path ) )
  by_line = by_line.gsub( '_', ' ' )   ## auto-convert underscore (_) back to space
  data.each do |rec|
    rec['by'] = by_line
  end
  data
end
read_builtin( name ) click to toggle source
# File lib/cryptoquotes.rb, line 17
def self.read_builtin( name )
  name = name.gsub( ' ', '_')   ## auto-convert spaces to underscore (_)
  read( "#{root}/data/#{name}.yml" )
end
root() click to toggle source
# File lib/cryptoquotes/version.rb, line 18
def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end
sources() click to toggle source
# File lib/cryptoquotes.rb, line 38
def self.sources    ## rename to authors or datafiles or such - why? why not?
  ['Amy_Castor',
   'Bitcoiner',
   'Crypto_US$_Stablecoin_Printer',
   'David_Gerard',
   'Frances_Coppola',
   'Nouriel_Roubini',
   'Patrick_McKenzie',
   'Preston_Byrne',
   'Trolly_McTrollface']
end
version() click to toggle source
# File lib/cryptoquotes/version.rb, line 10
def self.version
  VERSION
end