Class: StoryKey::Console
- Inherits:
-
Thor
- Object
- Thor
- StoryKey::Console
- Defined in:
- lib/story_key/console.rb
Defined Under Namespace
Classes: Recover
Instance Method Summary collapse
- #decode(story = nil) ⇒ Object
- #encode(key = nil) ⇒ Object
- #new(bitsize = StoryKey::DEFAULT_BITSIZE) ⇒ Object
- #recover ⇒ Object
Instance Method Details
#decode(story = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/story_key/console.rb', line 58 def decode(story = nil) story ||= File.read([:file]) format ||= [:format] puts StoryKey.decode(story:, format:) rescue StoryKey::InvalidVersion puts "Invalid version" exit rescue StoryKey::InvalidChecksum, StoryKey::InvalidWord puts "Invalid story" exit end |
#encode(key = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/story_key/console.rb', line 35 def encode(key = nil) key ||= File.read([:file]) story = StoryKey.encode(key:, format: [:format]) puts story_str(key, story) print_image_path(story.tokenized, story.phrases) if [:image] rescue StoryKey::InvalidFormat quit "Invalid format" rescue StoryKey::KeyTooLarge quit "Key too large" rescue Errno::ENOENT quit "Invalid file specified" end |
#new(bitsize = StoryKey::DEFAULT_BITSIZE) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/story_key/console.rb', line 13 def new(bitsize = StoryKey::DEFAULT_BITSIZE) key, story = StoryKey.generate(bitsize: bitsize.to_i) puts story_str(key, story) print_image_path(story.tokenized, story.phrases) if [:image] rescue StoryKey::KeyTooLarge quit "Key too large" end |
#recover ⇒ Object
71 72 73 |
# File 'lib/story_key/console.rb', line 71 def recover StoryKey.recover end |