class MultimediaParadise::LyricsFetcher

Constants

SEARCH_TERM
#

SEARCH_TERM

#

Public Class Methods

new( search_term = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 32
def initialize(
    search_term = nil,
    run_already = true
  )
  reset
  set_search_term(
    search_term
  )
  run if run_already
end

Public Instance Methods

feedback_available_titles() click to toggle source
#

feedback_available_titles

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 210
def feedback_available_titles
  _ = obtain_raw_dataset
  if _.is_a? Hash
    counter = 0
    cliner
    _.each_pair {|title, value|
      counter += 1
      e; e '('+counter.to_s.rjust(2)+') '+simp(title)
      e; e value; e
      cliner
    }
  end
end
fetch_subsections_from_dataset() click to toggle source
#

fetch_subsections_from_dataset

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 201
def fetch_subsections_from_dataset
  lyrics?.each {|line|
    e line.delete(',').delete('"') if line.include? 'add_song'
  }
end
load_yaml_dataset()
Alias for: obtain_raw_dataset
lyrics?() click to toggle source
#

lyrics?

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 194
def lyrics?
  @hash[:raw_dataset]
end
main_file?() click to toggle source
#

main_file?

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 72
def main_file?
  LYRICS_YAML_FILE
end
menu( i = @search_term ) click to toggle source
#

menu

The menu will, by default, try to find a proper title.

#
obtain_raw_dataset() click to toggle source
#

obtain_raw_dataset

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 91
def obtain_raw_dataset
  @hash[:raw_dataset] = nil
  begin
    @hash[:raw_dataset] = YAML.load_file(main_file?)
  rescue Exception => e
    pp e
  end
end
Also aliased as: raw_dataset?, load_yaml_dataset
open_yaml_file_in_editor() click to toggle source
#

open_yaml_file_in_editor

Invocation example:

lfetcher open
#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 109
def open_yaml_file_in_editor
  esystem "bluefish #{main_file?}"
end
raw_dataset?()
Alias for: obtain_raw_dataset
report(this = @hash[:text]) click to toggle source
#

report

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 175
def report(this = @hash[:text])
  # ======================================================================= #
  # Ok, we found it, so display it next:
  # ======================================================================= #
  cliner colour: :konsole_slateblue
  e this
  cliner colour: :konsole_slateblue
end
reset() click to toggle source
#

reset

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 46
def reset
  super()
  # ======================================================================= #
  # === @hash
  # ======================================================================= #
  @hash = {}
  infer_the_namespace
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 227
def run
  menu
  load_yaml_dataset
  fetch_subsections_from_dataset
end
set_search_term(i = SEARCH_TERM) click to toggle source
#

set_search_term

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 58
def set_search_term(i = SEARCH_TERM)
  if i.is_a? Array
    i = i.join(' ').strip
  end
  case i
  when nil, :default
    i = SEARCH_TERM
  end
  @search_term = i
end
show_file_path() click to toggle source
#

show_file_path

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 187
def show_file_path
  e LYRICS_YAML_FILE
end
show_help() click to toggle source
#

show_help (help tag)

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 79
def show_help
  opnn; e 'These options are available:'
  e
  opnn; e '  --file?            # Feedback the full path to the .yml '\
          'file in question'
  opnn; e '  --available_titles # Feedback the available titles'
  e
end
try_to_find_this_title(i) click to toggle source
#

try_to_find_this_title

This method will try to find an appropriate title.

#
# File lib/multimedia_paradise/audio/lyrics_fetcher.rb, line 157
def try_to_find_this_title(i)
  _ = raw_dataset?
  keys = _.keys.map
  possible_matches = keys.select {|entry|
    entry = entry.dup if entry.frozen?
    entry.downcase.include? i.downcase
  }
  if possible_matches.empty?
    opnn; e 'Did not find that particular key.'
  else
    @hash[:text] = _[possible_matches.first]
    report(@hash[:text])
  end
end