Class: Ankit::AddCommand
- Inherits:
-
TextReadingCommand
- Object
- Command
- TextReadingCommand
- Ankit::AddCommand
- Includes:
- CardNaming
- Defined in:
- lib/ankit/add_command.rb
Constant Summary
Constants inherited from Command
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
Methods included from CardNaming
#card_wildcard_for, #to_card_name, #to_card_path
Methods inherited from TextReadingCommand
Methods inherited from Command
available, by_name, command_name, define_options, #initialize, option_spec
Constructor Details
This class inherits a constructor from Ankit::Command
Instance Method Details
#dest_dir ⇒ Object
30 |
# File 'lib/ankit/add_command.rb', line 30 def dest_dir; [:dir] || runtime.config.card_paths[0]; end |
#execute ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ankit/add_command.rb', line 14 def execute() each_text do |text| text.split(/\n\n+/).map(&:strip).each do |chunk| next if chunk.empty? card = Card.parse(chunk) next unless card # TODO: gaurd ovewrite # TODO: guard out-of-path write filename = to_card_path(dest_dir, card.name) File.open(filename, "w") { |f| f.write(chunk) } runtime.stdout.write("#{filename}\n") end end end |