farmingengineers 0.1.4 → 0.1.5

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{farmingengineers}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Burke"]
data/invoice.rb CHANGED
@@ -3,13 +3,15 @@ $: << 'lib'
3
3
  require 'egg_csa_invoice'
4
4
 
5
5
 
6
- egg_csa_invoice do
6
+ egg_csa_invoice(:id => '20101008-001') do
7
7
  customer 'Sample customer'
8
8
  address ['123 Street', 'City, IN', '317-xxx-xxxx']
9
9
  deposit '8/1/2010', 500
10
10
  deliver '10/11/2010', 11
11
11
  deliver '10/11/2010', 4, :rate => 4.50
12
12
  egg delivery '10/12/2010', 1
13
+ line_item '11/1/2010', 'Another line item', 3, 4
14
+ line_item :date => '11/2/2010', :description => 'Another line item', :total => 5
13
15
  purchase '11/1/2010', 'Doughnuts', 10
14
16
  notes 'Notes to customer'
15
17
  end
@@ -5,7 +5,7 @@ require 'farming_engineers'
5
5
  module EggCsaInvoice
6
6
 
7
7
  $invoice_count = 0
8
- def egg_csa_invoice(&block)
8
+ def egg_csa_invoice(opts = {}, &block)
9
9
  invoice = FarmingEngineers::Invoices::Eggs::Invoice.new
10
10
  invoice.instance_eval(&block)
11
11
 
@@ -15,7 +15,7 @@ def egg_csa_invoice(&block)
15
15
  balance += line.total
16
16
  t << [line.date, line.description, line.quantity, d(line.total), d(balance)]
17
17
  end
18
- t << ['', '', '', 'TOTAL', d(balance)]
18
+ t << ['', '', '', opts[:total_label] || 'TOTAL', d(balance)]
19
19
  end
20
20
 
21
21
  history_table.rename_columns(
@@ -26,8 +26,8 @@ def egg_csa_invoice(&block)
26
26
  :balance => 'Balance'
27
27
  )
28
28
 
29
- invoice_id = "#{Date.today.strftime('%Y%m%d')}-#{$invoice_count += 1}"
30
- invoice_file = File.expand_path("../invoice-#{invoice_id}.pdf", $0)
29
+ invoice_id = opts[:id] || "#{Date.today.strftime('%Y%m%d')}-#{$invoice_count += 1}"
30
+ invoice_file = invoice_id + '.pdf'
31
31
  puts invoice_file
32
32
 
33
33
  Ruport::Controller::Invoice.render :pdf, :file => invoice_file do |i|
@@ -51,6 +51,6 @@ end
51
51
  extend self
52
52
  end
53
53
 
54
- def egg_csa_invoice(&block)
55
- EggCsaInvoice.egg_csa_invoice(&block)
54
+ def egg_csa_invoice(*args, &block)
55
+ EggCsaInvoice.egg_csa_invoice(*args, &block)
56
56
  end
@@ -12,18 +12,23 @@ module FarmingEngineers ; module Invoices ; module Common
12
12
  end
13
13
  end
14
14
 
15
- class History < Array
16
- def deposit date, amount
17
- push Deposit.new(date, amount)
18
- end
19
-
20
- def purchase date, description, amount
21
- push Purchase.new(date, description, amount)
22
- end
23
- end
24
15
  class HistoryItem
25
16
  attr_reader :date, :description, :quantity, :total
26
17
  end
18
+ class LineItem < HistoryItem
19
+ def initialize(*args)
20
+ case args.first
21
+ when Hash
22
+ args = args.first
23
+ @date = args[:date]
24
+ @description = args[:description]
25
+ @quantity = args[:quantity]
26
+ @total = args[:total]
27
+ else
28
+ @date, @description, @quantity, @total = args
29
+ end
30
+ end
31
+ end
27
32
  class Deposit < HistoryItem
28
33
  def initialize(date, amount)
29
34
  @date = date
@@ -38,4 +43,15 @@ module FarmingEngineers ; module Invoices ; module Common
38
43
  @total = amount
39
44
  end
40
45
  end
46
+ class History < Array
47
+ def self.generator(name, klass)
48
+ define_method(name) do |*args|
49
+ push klass.new(*args)
50
+ end
51
+ end
52
+ generator :deposit, Deposit
53
+ generator :purchase, Purchase
54
+ generator :line, LineItem
55
+ generator :line_item, LineItem
56
+ end
41
57
  end ; end ; end
@@ -6,19 +6,10 @@ module FarmingEngineers ; module Invoices ; module Eggs
6
6
  end
7
7
  end
8
8
 
9
- class History < Common::History
10
- def deliver date, dozens, opts = {}
11
- push Delivery.new(date, dozens, opts)
12
- end
13
- alias delivery deliver
14
- alias egg_delivery deliver
15
- def egg(*args) ; end
16
- end
17
-
18
9
  class Delivery < Common::HistoryItem
19
10
  def initialize(date, dozens, opts = {})
20
11
  @date = date
21
- @description = 'Delivery'
12
+ @description = 'Egg Delivery'
22
13
  @quantity = dozens
23
14
  @total = calculate opts.merge(:dozens => dozens)
24
15
  end
@@ -35,4 +26,11 @@ module FarmingEngineers ; module Invoices ; module Eggs
35
26
  end)
36
27
  end
37
28
  end
29
+
30
+ class History < Common::History
31
+ generator :deliver, Delivery
32
+ generator :delivery, Delivery
33
+ generator :egg_delivery, Delivery
34
+ def egg(*args) ; end
35
+ end
38
36
  end ; end ; end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farmingengineers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Burke