Commits

Chad Perrin committed 8e732c5

holy crap a lotta stuff for personator

  • Participants
  • Parent commits 9c299f1

Comments (0)

Files changed (1)

File bin/personator

 EOF
 
 help_text = {
-  :commands =>  'Display command list.',
-  :help     =>  'Display this help text.',
-  :version  =>  'Display version and license information.'
+  :commands     =>  'Display command list.',
+  :parameters   =>  'Specify comma separated special parameters.',
+  :help         =>  'Display this help text.',
+  :version      =>  'Display version and license information.'
 }
 
 command_text = {
-  :help         => 'Display command help.',
-  :birthdate    => 'Select characters filtered by ARGS and return' <<
-                   'birthdates and ages.  ARGS are compared against' <<
-                   'character names and contexts.'
+  :help         =>  'Display command help.',
+  :birthdate    =>  'Select characters filtered by ARGS and return ' <<
+                    'birthdates and ages.  ARGS are compared against ' <<
+                    'character names and contexts.  If no ARGS are ' <<
+                    'supplied, generate and return a random birthdate.',
+  :description  =>  'Select characters filtered by ARGS and return ' <<
+                    'description lists.  ARGS are compared against ' <<
+                    'character names and contexts.  If no ARGS are ' <<
+                    'supplied, generate and return a random appearance ' <<
+                    'list.',
+  :sexuality    =>  'Select characters filtered by ARGS and return ' <<
+                    'sexual identities and orientations.  ARGS are ' <<
+                    'compared against character names and contexts. ' <<
+                    'If no ARGS are supplied, generate and return a ' <<
+                    'random identity and orientation pair.'
 }
 
-@commands = @usage
+@commands = @usage.dup
 command_text.each do |c|
   @commands << "    #{c[0]} [ARGS]".ljust(37)
-  cmd_desc = wrap c[1], 37
+  cmd_desc = wrap c[1], 43
   @commands << cmd_desc[0] << "\n"
   1.upto(cmd_desc.length-1) do |n|
      @commands << ''.rjust(37)
 
 @data_dir    = File.join(ENV['HOME'], '.persona/data')
 
+params = Array.new
+
 OptionParser.new do |opts|
   opts.banner = @usage
 
+  opts.on('--parameters <ARG>', '-p', help_text[:parameters]) do |arg|
+    params = arg.split(',')
+  end
+
   opts.on('--commands', '-c', help_text[:commands]) do
     puts "\nCommand List:"
     puts
   end
 end.parse!
 
-@personator = YAML.load(File.open File.join(@config_dir, @config_file))
+@personator = YAML.load File.open File.join(@config_dir, @config_file)
 
 def bad_command
   puts @usage
   puts
 end
 
-def birthdate(args)
-  personae = Array.new
+def char_list(directory)
+  persona_list = Array.new
   Dir.entries(@data_dir).each do |fname|
     if fname.match(/yaml$/)
-      personae << Persona.open(fname.sub '.yaml', '')
+      persona_list << Persona.open(fname.sub '.yaml', '')
     end
   end
+  persona_list
+end
 
+def char_filter(personae, args)
   characters = Array.new
   args.each do |a|
     personae.each do |p|
       end
     end
   end
+  characters.uniq.sort {|a,b| a.name.to_s <=> b.name.to_s }
+end
 
-  characters.uniq!
-  characters.sort! {|a,b| a.name.to_s <=> b.name.to_s }
+def birthdate(args)
+  characters = char_filter char_list(@data_dir), args
 
   birthdays = Hash.new
   characters.each do |c|
     begin
       birthdays[c.name] = [c.birthday, c.age]
     rescue
-      birthdays[c.name] = ['n/a', 'n/a']
+      birthdays[c.name] = ['', '']
     end
   end
 
   birthdays
 end
 
+def description(args)
+  characters = char_filter char_list(@data_dir), args
+
+  descriptions = Hash.new
+  characters.each do |c|
+    begin
+      descriptions[c.name] = Array.new
+      c.description.each_pair do |k,list|
+        descriptions[c.name] << "#{k}:" <<  list.join(', ')
+      end
+    rescue
+    end
+  end
+
+  descriptions
+end
+
+def sexuality(args)
+  characters = char_filter char_list(@data_dir), args
+
+  sexualities = Hash.new
+  characters.each do |c|
+    begin
+      sexualities[c.name] = [c.identity, c.orientation]
+    rescue
+      sexualities[c.name] = ['', '']
+    end
+  end
+
+  sexualities
+end
+
+def reformat(meth)
+  d = self.send(meth, ARGV)
+  out = String.new
+
+  dnum = d[d.keys[0]].size
+  length = Array.new
+  0.upto(dnum) {|n| length[n] = 0 }
+
+  d.each_key {|k| if k.length > length[0] then length[0] = k.length end }
+
+  d.each_key do |k|
+    1.upto(dnum) do |n|
+      if (nlength = d[k][n-1].to_s.length) > length[n] then length[n] = nlength end
+    end
+  end
+
+  d.each_key do |k|
+    ch = [k.to_s.rjust(length[0]).dup]
+    0.upto(dnum - 1) {|n| ch << d[k][n].to_s.rjust(length[n+1]) }
+    out << ch.join('  ') + "\n"
+  end
+
+  out
+end
+
 if 0 < ARGV.size
   command = ARGV.shift
-  if command == 'birthdate'
-    length = 0
-    b = birthdate(ARGV)
-    b.each_key {|k| if k.length > length then length = k.length end }
-    b.each_key do |k|
-      print k.to_s.rjust(length + 2)
-      print b[k][0].to_s.rjust(15)
-      print b[k][1].to_s.rjust(7)
-      puts
+  keywords = ARGV
+  case command
+  when 'birthdate'
+    if keywords.size < 1
+      cal = if params.size > 0
+        params[0]
+      else
+        print 'Enter Calendar: '
+        gets.chomp
+      end
+
+      date = Persona.randbday cal
+      puts "#{date[:month]}-#{date[:day]}"
+    else
+      puts reformat command.to_sym
     end
-  elsif command == 'help'
+  when 'description'
+    if keywords.size < 1
+      gender = if params.size > 0
+        params[0]
+      else
+        print 'Enter Gender: '
+        gets.chomp
+      end
+
+      begin
+        appearance = Persona.random_appearance gender.downcase.to_sym
+        puts "appearance: #{appearance.join ', '}"
+      rescue
+        puts 'Please select "male" or "female" for gender.'
+      end
+    else
+      puts reformat command.to_sym
+    end
+  when 'sexuality'
+    if keywords.size < 1
+      sid = Persona.randsid
+      puts "#{sid}: #{Persona.randsor(sid).to_s.rjust 3}".rjust 17
+    else
+      puts reformat command.to_sym
+    end
+  when 'help'
     puts @commands
   else
     bad_command