Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Retroactive readme-driven development: rename API methods

  • Loading branch information...
commit 0340fa755c7d4cb6695f088e14bb50868caf4013 1 parent 394dc0a
@dvrensk dvrensk authored
Showing with 17 additions and 7 deletions.
  1. +12 −7 README.md
  2. +5 −0 lib/bankgiro_inbetalningar.rb
View
19 README.md
@@ -20,14 +20,14 @@ Or install it yourself as:
## Usage
-Use the convenience method `BankgiroInbetalningar.parse` to parse a file
-or `BankgiroInbetalningar.parse_data` to parse a string:
+Use the convenience method `BankgiroInbetalningar.parse_file` to parse a file
+or `BankgiroInbetalningar.parse_string` to parse a string:
```ruby
-res = BankgiroInbetalningar.parse("BgMaxfil4.txt")
+res = BankgiroInbetalningar.parse_file("BgMaxfil4.txt")
# Or
data = File.read("BgMaxfil4.txt").force_encoding("ISO-8859-1")
-res = BankgiroInbetalningar.parse_data(data)
+res = BankgiroInbetalningar.parse_string(data)
raise "oops" unless res.valid?
# You can process deposit by deposit...
@@ -50,13 +50,13 @@ the raw data along with each deposit or payment in a database. Note that the
currency name only is available in the deposit:
```ruby
-payment_1 = BankgiroInbetalningar.parse("BgMaxfil4.txt").payments.first
-payment_2 = BankgiroInbetalningar.parse_data(payment_1.raw).payments.first
+Dir.chdir 'spec/fixtures'
+payment_1 = BankgiroInbetalningar.parse_file("BgMaxfil4.txt").payments.first
+payment_2 = BankgiroInbetalningar.parse_string(payment_1.raw).payments.first
payment_1.cents # => 180000
payment_2.cents # => 180000
payment_1.currency # => "SEK"
payment_2.currency # => nil
-
```
See the specs for more details.
@@ -65,6 +65,11 @@ Files are expected to be ISO-8859-1 (as Bankgirot prefers), but data strings
can be in any encoding, as long as `String#encoding` is correct. The library
returns UTF-8. It *is* the 21st century.
+## Changes
+
+The methods `parse_file` and `parse_string` are also available under their
+old names `parse` and `parse_data`.
+
## Todo / Missing features
`BankgiroInbetalningar` works well enough for our needs, so there are no plans for
View
5 lib/bankgiro_inbetalningar.rb
@@ -13,4 +13,9 @@ def self.parse_data(data)
parser.run
parser.result
end
+
+ class << self
+ alias parse_file parse
+ alias parse_string parse_data
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.