-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interim checkin - work on user parser
- Loading branch information
1 parent
0a643af
commit deae3d6
Showing
6 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ log/* | |
arkham.hect/* | ||
.capistrano/metrics | ||
alice.log | ||
user_setup.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Parser | ||
class User | ||
def self.fetch(topic) | ||
user = ::User.from(topic) | ||
content = user_methods(user).map do |method| | ||
string_from_user_info(user, method) | ||
end.flatten.reject(&:empty?).join('. ').gsub('.. ', '. ') | ||
end | ||
|
||
def self.user_methods(user) | ||
user.methods.select { |m| /^info_/.match(m) && user.method(m).arity.zero? } | ||
end | ||
|
||
def self.string_from_user_info(user, method_name) | ||
info = user.public_send(method_name) | ||
is_boolean = /\?/.match(method_name) | ||
return(info) unless is_boolean | ||
info ? positive_response_for(user, method_name) : negative_response_for(user, method_name) | ||
rescue | ||
"" | ||
end | ||
|
||
def self.scrub_method_name(method_name) | ||
method_name.to_s.gsub(/^info_|\?/, '').gsub('_', ' ') | ||
end | ||
|
||
def self.positive_response_for(user, method) | ||
"#{user.current_nick} #{scrub_method_name(method)}".gsub(/can([^ ])/, 'can \1') | ||
end | ||
|
||
def self.negative_response_for(method) | ||
"#{user.current_nick} is not #{scrub_method_name(method)}".gsub(/can[^ ]/, 'can not \1') | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters