Module: Quotes

Defined in:
lib/cryptoquotes.rb,
lib/cryptoquotes/version.rb

Constant Summary collapse

MAJOR =
1
MINOR =
1
PATCH =
0
VERSION =
[MAJOR,MINOR,PATCH].join('.')

Class Method Summary collapse

Class Method Details

.allObject



50
51
52
53
54
55
56
57
# File 'lib/cryptoquotes.rb', line 50

def self.all
  @all ||= begin
              all = []
              sources.each { |source| all += read_builtin( source ) }
              all
           end
  @all
end


14
15
16
# File 'lib/cryptoquotes/version.rb', line 14

def self.banner
  "cryptoquotes/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] (in #{root})"
end

.lotteryObject



62
63
64
65
# 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

.randomObject

get a random quote



67
68
69
70
71
# 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) ⇒ Object

read-in a quote dataset - returns an array of hash records



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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
   = File.basename( path, File.extname( path ) )
   = .gsub( '_', ' ' )   ## auto-convert underscore (_) back to space
  data.each do |rec|
    rec['by'] = 
  end
  data
end

.read_builtin(name) ⇒ Object



17
18
19
20
# 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

.rootObject



18
19
20
# File 'lib/cryptoquotes/version.rb', line 18

def self.root
  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end

.sourcesObject

rename to authors or datafiles or such - why? why not?



38
39
40
41
42
43
44
45
46
47
48
# 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

.versionObject



10
11
12
# File 'lib/cryptoquotes/version.rb', line 10

def self.version
  VERSION
end