Class: ExpandSync::AText
- Inherits:
-
Object
- Object
- ExpandSync::AText
- Defined in:
- lib/expandsync/atext.rb
Overview
AText Class
Constant Summary collapse
- OUTPUT_FILENAME =
The output filename
'aText-snippets.csv'
- OUTPUT_PATH =
The output filepath
ENV['HOME']
Instance Attribute Summary collapse
-
#output_file ⇒ String
Stores the output filepath.
-
#snippet_csv ⇒ String
Stores a CSV string of the snippets.
-
#snippets ⇒ Array
Stores an array of snippets.
Instance Method Summary collapse
-
#construct_data(new_snippets) ⇒ String
Outputs a CSV listing of the supplied snippets.
-
#initialize(csv_filepath, custom_output_path) ⇒ void
constructor
Initialize by loading snippets from an aText CSV.
-
#save ⇒ void
Saves the current snippets to Settings.textexpander.
Constructor Details
#initialize(csv_filepath, custom_output_path) ⇒ void
Initialize by loading snippets from an aText CSV.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/expandsync/atext.rb', line 27 def initialize(csv_filepath, custom_output_path) if custom_output_path.nil? @output_file = File.join(OUTPUT_PATH, OUTPUT_FILENAME) else if Dir.exists?(File.dirname(custom_output_path)) @output_file = custom_output_path else fail "Invalid output directory for aText: #{ custom_output_path }" end end if File.exists?(csv_filepath) && File.extname(csv_filepath) == '.csv' begin @snippets = CSV.read(csv_filepath) rescue fail "Could not load CSV from file: #{ csv_filepath }" end @snippets.each { |s| s[2] = 'aText' } else fail "Invalid CSV file: #{ csv_filepath }" end end |
Instance Attribute Details
#output_file ⇒ String
Stores the output filepath.
14 15 16 |
# File 'lib/expandsync/atext.rb', line 14 def output_file @output_file end |
#snippet_csv ⇒ String
Stores a CSV string of the snippets.
18 19 20 |
# File 'lib/expandsync/atext.rb', line 18 def snippet_csv @snippet_csv end |
#snippets ⇒ Array
Stores an array of snippets.
22 23 24 |
# File 'lib/expandsync/atext.rb', line 22 def snippets @snippets end |
Instance Method Details
#construct_data(new_snippets) ⇒ String
Outputs a CSV listing of the supplied snippets
54 55 56 |
# File 'lib/expandsync/atext.rb', line 54 def construct_data(new_snippets) @snippet_csv = CSV.generate { |csv| new_snippets.each { |s| csv << [s[0], s[1]] } } end |
#save ⇒ void
This method returns an undefined value.
Saves the current snippets to Settings.textexpander.
60 61 62 |
# File 'lib/expandsync/atext.rb', line 60 def save File.open(@output_file, 'w') {|f| f.write(@snippet_csv) } end |