Class: GamesAndRpgParadise::Lpc::KnowledgeBase

Inherits:
Base
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb

Constant Summary collapse

LPC_FILE =
#

LPC_FILE

#
'/home/x/rpg/muds/geas/wizard/LPC_CODE_SHEET.md'

Constants included from Base::Extensions::Colours

Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS

Constants included from CommonExtensions

CommonExtensions::CONTROL_C_CODE, CommonExtensions::N

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base::Extensions::Colours

ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow

Methods included from Base::Extensions::CommandlineArguments

#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments

Methods included from CommonExtensions

#cat, #cd, #cliner, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into

Constructor Details

#initialize(optional_search_for = nil, run_already = true) ⇒ KnowledgeBase

#

initialize

#


27
28
29
30
31
32
33
34
35
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 27

def initialize(
    optional_search_for = nil,
    run_already         = true
  )
  set_search_for(
    optional_search_for
  )
  run if run_already
end

Class Method Details

.file?Boolean

#

GamesAndRpgParadise::Lpc::KnowledgeBase.file?

#

Returns:

  • (Boolean)


50
51
52
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 50

def self.file? # Just a query method.
  return LPC_FILE
end

Instance Method Details

#assign_to_tag(i) ⇒ Object

#

assign_to_tag

#


103
104
105
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 103

def assign_to_tag(i)
  @tag = i.downcase
end

#lpc_file?Boolean

#

lpc_file?

#

Returns:

  • (Boolean)


126
127
128
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 126

def lpc_file?
  LPC_FILE
end

#read_lpc_fileObject

#

read_lpc_file

#


119
120
121
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 119

def read_lpc_file
  @file = File.readlines(lpc_file?)
end

#report_to_userObject

#

report_to_user

#


71
72
73
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 71

def report_to_user
  e GREEN+'We have '+YEL+@n_keys+GREEN+' keys (Tags).'
end

#resetObject

#

reset

#


40
41
42
43
44
45
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 40

def reset
  @all_tags = nil
  @hash_tag_data = {}
  @tag = ''
  @data = ''
end

#runObject

#

run

#


152
153
154
155
156
157
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 152

def run
  read_lpc_file
  store_data_into_main_hash
  report_to_user
  search_for_tag
end

#save_dataObject

#

save_data

#


110
111
112
113
114
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 110

def save_data
  @hash_tag_data[@tag] = @data
  @tag = '' # and also remove the old one.
  @data = ''.dup
end

#search_for?Boolean

#

search_for?

#

Returns:

  • (Boolean)


57
58
59
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 57

def search_for?
  @search_for
end

#search_for_tag(i = search_for?) ) ⇒ Object

#

search_for_tag

#


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 133

def search_for_tag(i = search_for?)
  if i
    e GREEN+'Searching for tag: `'+YELLOW+i+GREEN+'` now (in file '+lpc_file?+').'
    matches = @all_tags.select {|t| t =~ /#{i}/}
    if matches and ! matches.empty?
      matches.each { |key|
        e GREEN+key
        e YELLOW+@hash_tag_data[key]
        cliner 
      }
    else
      warn 'No match could be found for `'+GREEN+i+RED+'`.'
    end
  end
end

#set_search_for(i = nil) ⇒ Object

#

set_search_for

#


64
65
66
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 64

def set_search_for(i = nil)
  @search_for = i
end

#store_data_into_main_hashObject

#

store_data_into_main_hash

#


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/games_and_rpg_paradise/lpc/utility_scripts/knowledge_base.rb', line 78

def store_data_into_main_hash
  reset
  # ======================================================================== #
  # Here we use a simple strategy to obtain the data we want. If it has 
  # two leading spaces, it is considered content. Otherwise, it is 
  # considered a tag. If that latter tag has not the keyword tag, we
  # assume the first word is the tag.
  # ======================================================================== #
  @file.each { |line|
    line = line.chomp
    next if line.empty?
    if line.start_with? ' '
      @data << line+N
    else
      save_data
      assign_to_tag(line)
    end
  }
  @all_tags = @hash_tag_data.keys
  @n_keys = @all_tags.size.to_s
end