-
Notifications
You must be signed in to change notification settings - Fork 30
becometh a knight today #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sampriddy
wants to merge
12
commits into
paircolumbus:master
Choose a base branch
from
sampriddy:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
675da1e
Get large portion of MVCgame working
8d00e0b
Update controller to fix logic bug
9f937c5
Get new translation saves working
c0c7d75
DRY confirmation logic
fa4a0b4
Add deletion logic and make add entry method check if entry already e…
6d290fc
Add update method, basic CRUD works
8953643
Move some logic from controller to model where appropriate
4ad315f
Move delete method to model from controller
2885419
Remove unrelated files
734f774
Change filename schema.json to translations.json
7bc49b8
Change gets.chomp in TranslatorController#pause to get_input
b90d1a2
Expand translations.json
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,131 @@ | ||
| require_relative 'view' | ||
| require_relative 'model' | ||
| require 'json' | ||
| require 'pry' | ||
|
|
||
| class TranslatorController | ||
| attr_accessor :translation_dict | ||
|
|
||
| include TranslatorView | ||
| include TranslatorModel | ||
|
|
||
| def initialize | ||
| @translation_dict = Schema::import_translation_schema | ||
| end | ||
|
|
||
| def translate string | ||
| words = string.scan Schema::WORDS_REGEX | ||
| translated_words = words.collect { |w| @translation_dict[w] || w } | ||
| translated_words.join " " | ||
| end | ||
|
|
||
| def play | ||
| Display::title | ||
| pause | ||
| user_input = nil | ||
|
|
||
| until ['quit', 'q', 'exit', 'e'].include? user_input | ||
| Display::menu | ||
| user_input = gets.chomp.downcase | ||
| case user_input | ||
| when 'v' then Display::print_schema(translation_dict) | ||
| when 'a' then add_new_entry | ||
| when 'u' then update_entry | ||
| when 'd' then delete_entry | ||
| when 's' then save_schema | ||
| else | ||
| puts translate user_input | ||
| end | ||
| pause | ||
| end | ||
| puts "~ Fare thee well ~" | ||
| end | ||
|
|
||
| def pause | ||
| Display::pause | ||
| get_input | ||
| end | ||
|
|
||
| def get_input | ||
| gets.chomp.downcase | ||
| end | ||
|
|
||
| def confirm? | ||
| ['y', 'yes'].include? get_input | ||
| end | ||
|
|
||
| def add_new_entry | ||
| Display::request_english_word | ||
| original = get_input | ||
|
|
||
| if @translation_dict[original] | ||
| puts "Translation already exists; use (U)pdate to modify." | ||
| return | ||
| end | ||
|
|
||
| Display::request_translation | ||
| translated = get_input | ||
|
|
||
| puts "Save new translation: #{original} => #{translated}?" | ||
| if confirm? | ||
| Schema::update_entry(@translation_dict, original, translated) | ||
| #@translation_dict[original] = translated | ||
| puts "Change saved." | ||
| else | ||
| puts "Change rejected." | ||
| end | ||
| end | ||
|
|
||
| def save_schema | ||
| puts "Save current translation schema to file?" | ||
| if confirm? | ||
| Schema::export_translation_schema(@translation_dict) | ||
| puts "New schema saved." | ||
| else | ||
| puts "Schema changes cancelled." | ||
| end | ||
| end | ||
|
|
||
| def delete_entry | ||
| Display::request_english_word | ||
| target = get_input | ||
|
|
||
| case | ||
| when (@translation_dict.keys.include? target) | ||
| puts "Destroy #{target} => #{@translation_dict[target]}?" | ||
| if confirm? | ||
| Schema::destroy_entry(@translation_dict, target) | ||
| puts "Translation deleted." | ||
| else | ||
| puts "Canceling deletion." | ||
| end | ||
| else | ||
| puts "Translation not found in current schema. Returning to menu." | ||
| end | ||
| end | ||
|
|
||
| def update_entry | ||
| Display::request_english_word | ||
| target = get_input | ||
|
|
||
| case | ||
| when @translation_dict.keys.include?(target) | ||
| puts "Current translation: #{target} => #{@translation_dict[target]}" | ||
| puts "Enter new translation for this word." | ||
| new_translation = get_input | ||
|
|
||
| puts "Save updated entry: #{target} => #{new_translation}?" | ||
| if confirm? | ||
| Schema::update_entry(@translation_dict, target, new_translation) | ||
| #@translation_dict[target] = new_translation | ||
| puts "Entry updated." | ||
| else | ||
| puts "Canceled update." | ||
| end | ||
| else puts "No entry found to update. Use (A)dd to enter a new entry." | ||
| end | ||
| end | ||
| end | ||
|
|
||
| translator = TranslatorController.new | ||
| translator.play | ||
This file contains hidden or 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,35 @@ | ||
| #needs to get data from dictionary file (let's call it translation_dict.json)' | ||
|
|
||
| #define here methods for: | ||
| #retrieving entry data for viewing | ||
| #adding new entries | ||
| #updating entries | ||
| #deleting entries | ||
| #saving current translation dictionary to file | ||
|
|
||
| require 'json' | ||
|
|
||
| module TranslatorModel | ||
| module Schema | ||
| WORDS_REGEX = /\w+[a-z']*/ | ||
| class << self | ||
| def import_translation_schema source = 'translations.json' | ||
| JSON.parse(File.new(source).read) | ||
| end | ||
|
|
||
| def export_translation_schema(translation_dict, target = 'translations.json') | ||
| File.open(target, "w") do |f| | ||
| f.write(JSON.dump(translation_dict)) | ||
| end | ||
| end | ||
|
|
||
| def update_entry(target_dict, original, translated) | ||
| target_dict[original] = translated | ||
| end | ||
|
|
||
| def destroy_entry(target_dict, entry_key) | ||
| target_dict.delete entry_key | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 @@ | ||
| {"hello":"what ho!","wait":"tarry","you":"thou","can":"mayst","drunk":"besotted","sir":"sire","lazy":"distemperate","here":"hither","there":"thither","ugh":"fie","have":"han","do":"doeth","say":"sayeth","mine":"mineth","would":"wouldst","go":"goeth","get":"geteth","when":"whenst","horse":"steed","pass":"passeth","starve":"wasteth away","my":"mineth","are":"art","why":"wherefore","slob":"lout","should":"shouldst","boss":"liege","where":"whence","destroy":"slay","truly":"verily","bum":"rapscallion","away":"hence","trash":"rubbish","doctor":"apothecary","hey":"hark","dirty":"sullied","kill":"slay","happens":"passeth","shirt":"surcoat","take":"taketh","insult":"besmirch","decorate":"bedight","before":"ere","actually":"forsooth","peninsula":"ness","often":"oft","pan":"pannikin","tough":"stalwart","prevent":"thwart","reject":"forswear","old":"wizened","whimsical":"flighty","sleepy":"bedward","argue":"brabble","stuffed":"crapulous","matted":"elflocked","confuse":"jargogle","enjoy":"deliciate","silly":"ludibrious","dismal":"malagruous","quarrel":"brabble","binge":"brannigan","fool":"hoddypeak","alcoholism":"bibesy","confusion":"widdendream","careless":"yemeles","yourself":"thyself","twilight":"twitter-light","attractive":"illecebrous","schmoozer":"snecklifter","hungry":"famelicose","although":"al be that","also":"als","immediately":"anon","unless":"but if","chance":"aventure","better":"bet","know":"konne","case":"caas","counsel":"conseil","courage":"corage","every":"everich","judge":"deeme","doubt":"drede","eyes":"eyen","eye":"ye","befall":"falle","glad":"fayne","evil":"foul","from":"fro","free":"fre","did":"gan","luck":"hap","same":"ilke","let":"lat","rude":"lewed","little":"lyte","like":"lyke","dear":"leve","mastery":"maistry","much":"michel","may":"moot","more":"mo","not":"nat","nor":"ne","weren't":"nere","wouldn't":"nolde","isn't":"nys","perhaps":"peraventure","ignorant":"nyce","said":"quod","advice":"reede","certainly":"sikerly","certain":"siker","blessed":"sely","opinion":"sentence","solace":"solas","truthfulness":"soothfastness","stop":"stente","dream":"sweven","such":"swich","prosper":"theen","wary":"war","true":"verray","jump":"sterte","will":"wol","knew":"wiste","once":"whilom","supposed":"wende","knows":"woot","gave":"yaf","new":"yep","if":"yif","surely":"ywis"} |
This file contains hidden or 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,100 @@ | ||
| #to-do: | ||
| #add views methods for: | ||
| # add menu | ||
| # update menu | ||
|
|
||
|
|
||
|
|
||
| module TranslatorView | ||
| module Display | ||
| class << self | ||
| def title | ||
| title = <<TITLE | ||
|
|
||
| WHAT HO! | ||
| THOU SHALL BECOME KNIGHTLY | ||
| WITH MINE AMAZING KNIGHTLY TRANSLATOR | ||
|
|
||
| ,;~;, | ||
| /\_ | ||
| ( / | ||
| ((), ;,; | ||
| | \\ ,;;'( | ||
| __ _( )'~;;' \ | ||
| /' '\'()/~' \ /'\.) | ||
| ,;( )|| | | ||
| ,;' \ /-(.;, ) | ||
| ) / ) / | ||
| // || | ||
| (_\ (_\ | ||
|
|
||
| ***** PRESS ANY KEY TO CONTINUE ***** | ||
|
|
||
| TITLE | ||
| puts title | ||
| end | ||
|
|
||
| def menu | ||
|
|
||
| menu = <<MENU | ||
|
|
||
| | l~~~~~~~l | | ||
| /\ l^^^^^^^^^^^^^^^l /\ | ||
| /__\ _l O O O O O l_/__\ | ||
| l l l l l | ||
| l l l l l | ||
| [^^^] l [^^^] [^^^] l [^^^] | ||
| [ o ]-------------[ o ]-------------[ o ]-------------[ o ] | ||
| [ ] [ ] ___ [ ] [ ] | ||
| [ ] [ ] / \ [ ] [ ] | ||
| [ ] [ ] | | [ ] o [ ] | ||
| [ ] [ ] | | [ ]~\_|_ [ ] | ||
| [___]_____________[___]___|_____|___[___]_/\_/\_______[___]__ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are dope |
||
|
|
||
|
|
||
|
|
||
| ********** HARK! ************ | ||
| - Enter text to knightify, OR | ||
| - (V)iew translation schema | ||
| - (A)dd a new translation | ||
| - (U)pdate a translation | ||
| - (D)elete a translation | ||
| - (S)ave schema to file | ||
| - (Q)uit program | ||
| ********** ************* | ||
| MENU | ||
| puts menu | ||
| end | ||
|
|
||
| def print_schema source | ||
| puts "ORIGINAL // TRANSLATED" | ||
| source.each do |original, translated| | ||
| puts"#{original} => #{translated}" | ||
| end | ||
| end | ||
|
|
||
| def pause | ||
| puts "Press enter to continue" | ||
| end | ||
|
|
||
| def request_english_word | ||
| puts "Please enter the modern english word for the entry" | ||
| end | ||
|
|
||
| def request_translation | ||
| puts "Please enter the knightly translation" | ||
| end | ||
|
|
||
| def confirm? | ||
| puts "Save changes? Y" | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| #p TranslatorView::Display.methods.sort | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have this get_input method but then on line 29 you repeat this code. Maybe use this method there instead?