csv2qif 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,11 @@ require 'yaml'
4
4
  module Csv2qif
5
5
  class CLI
6
6
  DEFAULT_OPTIONS = {
7
- :field_separator => ',',
8
- :header => 1,
9
- :date => "a",
10
- :amount => "b",
11
- :type => 'CCard'
7
+ :field_separator => ',',
8
+ :header => 1,
9
+ :date => "a",
10
+ :amount => "b",
11
+ :type => 'CCard'
12
12
 
13
13
  }
14
14
 
@@ -18,7 +18,7 @@ module Csv2qif
18
18
 
19
19
  options = {
20
20
 
21
- }
21
+ }
22
22
 
23
23
  mandatory_options = %w( )
24
24
 
@@ -45,13 +45,15 @@ module Csv2qif
45
45
  BANNER
46
46
  opts.separator ""
47
47
  opts.on("-b", "--bundle BUNDLE", String,
48
- "Name of an option bundle",
49
- "Default: default") { |arg| options[:bundle] = arg }
48
+ "Name of an option bundle",
49
+ "Default: default") { |arg| options[:bundle] = arg }
50
50
  opts.on("-t", "--type Type", ['CCard', 'Bank', 'Cash'],
51
- "Type of acoount: CCard, Bank or Cash",
52
- "Default: CCard") { |arg| options[:type] = arg }
53
- opts.on("-w", "--where CONDITION",
51
+ "Type of acoount: CCard, Bank or Cash",
52
+ "Default: CCard") { |arg| options[:type] = arg }
53
+ opts.on("-w", "--where CONDITION",
54
54
  "only records satisfying CONDITION will be converted") { |arg| options[:where] = arg }
55
+ opts.on("-e", "--encoding ENCODING",
56
+ "encoding of the csv file") { |arg| options[:encoding] = arg }
55
57
  opts.on("-s", "--field_separator SEPARATOR",
56
58
  "field seprator. Default: ,") { |arg| options[:where] = arg }
57
59
  opts.on("-m", "--mappings MAPPINGS",
@@ -64,10 +66,10 @@ module Csv2qif
64
66
  opts.on("-h", "--help",
65
67
  "Show this help message.") { stdout.puts opts; return }
66
68
  opts.separator " "
67
-
69
+
68
70
  opts.separator "QIF Record options:"
69
71
  QIF::QIF_CODES.each do |key, code, description|
70
- opts.on("-#{code}", "--#{key} COLUMN", String, description || key.to_s.capitalize) {|arg| options[key]=arg}
72
+ opts.on("-#{code}", "--#{key} COLUMN", String, description || key.to_s.capitalize) { |arg| options[key]=arg }
71
73
  end
72
74
 
73
75
  opts.parse!(arguments)
@@ -102,7 +104,7 @@ module Csv2qif
102
104
  end
103
105
 
104
106
  def self.load_file bundle, qif=nil
105
- ['.', File.join( File.dirname(__FILE__), "../../config")].each do |dir|
107
+ ['.', File.join(File.dirname(__FILE__), "../../config")].each do |dir|
106
108
  [:rb, :yml].each do |type|
107
109
  if h = (File.exists?(file=File.join(dir, [bundle, type].join('.'))) and send "load_#{type}".to_sym, file, qif)
108
110
  return h
@@ -121,7 +123,7 @@ module Csv2qif
121
123
 
122
124
  def self.prepare_mappings options
123
125
  options[:mappings] = options[:mappings].map do |m|
124
- m = m.split(m[0,1])[1,3] unless m.instance_of? Array
126
+ m = m.split(m[0, 1])[1, 3] unless m.instance_of? Array
125
127
  m.unshift true if m.length < 3
126
128
  m[1]=Regexp.new(m[1])
127
129
  m
@@ -12,7 +12,8 @@ class Processor
12
12
  process_file stdin, stdout, options
13
13
  else
14
14
  arguments.each do |file|
15
- stream_in = File.open(file, "r")
15
+ mode = ['r', options[:encoding]].compact.join(':')
16
+ stream_in = File.open(file, mode)
16
17
  stream_out = File.new esub(file, :csv, :qif), "w"
17
18
  begin
18
19
  process_file stream_in, stream_out, options
@@ -1,3 +1,3 @@
1
1
  module Csv2qif
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv2qif
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-18 00:00:00.000000000 Z
12
+ date: 2012-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec