<commit_before>require 'ostruct'
require 'librarian'

class Actor
  def initialize role
    @character = role.new
  end
  
  def perform task
    task.perform_as @character
  end
  alias :answer :perform
end

class SubjectMatterExpert
  include Librarian  
  def how_do_i_perform this_task, *these_details 
    task = class_for( this_task )
    if task_requires_details?(task) 
      task.new(*with_arguments_from(these_details))
    else
      task.new 
    end
  end
  alias :how_do_i_answer :how_do_i_perform
    
  def task_requires_details? task
    task.instance_method(:initialize).arity > 0 
  end

  def with_arguments_from details
    argument_pattern = /('[^']+')/
    details.collect do |detail|
      OpenStruct.new Hash[*detail.split(argument_pattern).collect { |e| e.gsub('\'', '').strip.gsub(' ', '_') }]
    end
  end
end

Before do
    @sme = @sme ||= SubjectMatterExpert.new
end

Given /^I am a ([a-zA-Z ]+)$/ do |role|
  @actor = Actor.new(@sme.class_for role)
end

When /^I (?:attempt to|was able to)? ([^']*)$/ do |this_task|
  task = @sme.how_do_i_perform this_task
  @actor.perform task
end

When /^I (?:attempt to|was able to)? ([A-Z a-z_-]*): (.*)$/ do |this_task, with_these_details|
  task = @sme.how_do_i_perform this_task, with_these_details
  @actor.perform task
end

Then /^I should ([^']*) '([^']*)'$/ do |this_question, expect_value|
  question = @sme.how_do_i_answer this_question
  @actor.answer( question ).to_s.should == expect_value
end<commit_msg>Refactoring: The actor asks the subject matter expert how to perform a role or a task in that role //@antonymarcano<commit_after>require 'ostruct'
require 'librarian'

class Actor
  def initialize role_description
    @sme = SubjectMatterExpert.new
    @character = @sme.how_do_i_perform role_description
  end
  
  def perform this_task, *with_these_details
    task = @sme.how_do_i_perform this_task, *with_these_details
    task.perform_as @character
  end
  alias :answer :perform
end

class SubjectMatterExpert
  include Librarian  
  def how_do_i_perform this_something, *these_details 
    something = class_for( this_something )
    if details_required_for?(something) 
      something.new(*with_arguments_from(these_details))
    else
      something.new 
    end
  end
  alias :how_do_i_answer :how_do_i_perform
    
  def details_required_for? something
    something.instance_method(:initialize).arity > 0 
  end

  def with_arguments_from details
    argument_pattern = /('[^']+')/
    details.collect do |detail|
      OpenStruct.new Hash[*detail.split(argument_pattern).collect { |e| e.gsub('\'', '').strip.gsub(' ', '_') }]
    end
  end
end

Before do
    @sme = @sme ||= SubjectMatterExpert.new
end

Given /^I am a ([a-zA-Z ]+)$/ do |role|
  @actor = Actor.new(role)
end

When /^I (?:attempt to|was able to)? ([^']*)$/ do |this_task|
  @actor.perform this_task
end

When /^I (?:attempt to|was able to)? ([A-Z a-z_-]*): (.*)$/ do |this_task, with_these_details|
  @actor.perform this_task, with_these_details
end

Then /^I should ([^']*) '([^']*)'$/ do |this_question, expect_value|
  @actor.answer( this_question ).to_s.should == expect_value
end
{'fraction_non_alphanumeric': 0.12884798476674073, 'fraction_numerical': 0.0006347191367819739, 'mean_word_length': 3.8868217054263567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5551834', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1113, 'n_words': 270}