rescpos 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,21 +51,27 @@ module Rescpos
51
51
  def table(data)
52
52
  table = Rescpos::Table.new(data)
53
53
  yield table
54
+ # FIXME move the following logic into Rescpos::Table
54
55
  command = "\x1b\x44"
55
56
  table.positions.each do |position|
56
57
  command << position.chr
57
58
  end
58
59
  command << "\x00"
60
+ table.headers.each do |header|
61
+ command << header << "\x09"
62
+ end
63
+ command << "\n"
59
64
  table.data.each do |item|
60
65
  table.keys.each do |key|
61
- begin
62
- if item[key]
63
- command << "#{item[key]}"+"\x09"
64
- end
65
- rescue
66
- command << "#{item.send(key)}"+"\x09"
66
+ if item.is_a? Hash
67
+ command << "#{item[key]}"+"\x09"
68
+ else
69
+ command << "#{item.send(key)}"+"\x09"
67
70
  end
68
71
  end
72
+ if table.data.at(-1) == item
73
+ return command
74
+ end
69
75
  command << "\n"
70
76
  end
71
77
  command
data/lib/rescpos/table.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  module Rescpos
2
2
  class Table
3
- attr_reader :data, :positions, :keys
3
+ attr_reader :data, :positions, :keys, :headers
4
4
  def initialize(data)
5
5
  @data = data
6
6
  end
7
+ def head(headers)
8
+ @headers = headers
9
+ end
7
10
 
8
11
  def config(positions)
9
12
  @positions = positions
@@ -1,3 +1,3 @@
1
1
  module Rescpos
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -5,7 +5,7 @@ class ReportUtilTest
5
5
  include Rescpos::ReportUtil
6
6
  end
7
7
 
8
- class BillItemTest
8
+ class BillItem
9
9
  attr_accessor :name, :quantity
10
10
  end
11
11
 
@@ -62,20 +62,22 @@ describe ReportUtilTest do
62
62
  :quantity => 2,
63
63
  }
64
64
  table = @report_util.table([bill_item]) do |t|
65
+ t.head(["a", "b"])
65
66
  t.config([9])
66
67
  t.td([:name, :quantity])
67
68
  end
68
- table.should == "\x1b\x44#{9.chr}\x00a\x092\x09\n"
69
+ table.should == "\x1b\x44#{9.chr}\x00a\x09b\x09\na\x092\x09"
69
70
  end
70
71
 
71
72
  it "give a object should return a table" do
72
- bill_item = BillItemTest.new
73
+ bill_item = BillItem.new
73
74
  bill_item.name = 'a'
74
75
  bill_item.quantity = 2
75
76
  table = @report_util.table([bill_item]) do |t|
77
+ t.head(["a", "b"])
76
78
  t.config([9])
77
79
  t.td([:name, :quantity])
78
80
  end
79
- table.should == "\x1b\x44#{9.chr}\x00a\x092\x09\n"
81
+ table.should == "\x1b\x44#{9.chr}\x00a\x09b\x09\na\x092\x09"
80
82
  end
81
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rescpos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-31 00:00:00.000000000Z
12
+ date: 2011-09-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-inotify
16
- requirement: &82882830 !ruby/object:Gem::Requirement
16
+ requirement: &83465280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *82882830
24
+ version_requirements: *83465280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: libnotify
27
- requirement: &82882360 !ruby/object:Gem::Requirement
27
+ requirement: &83464000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *82882360
35
+ version_requirements: *83464000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-instafail
38
- requirement: &82881740 !ruby/object:Gem::Requirement
38
+ requirement: &83463570 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *82881740
46
+ version_requirements: *83463570
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber
49
- requirement: &82880970 !ruby/object:Gem::Requirement
49
+ requirement: &83462720 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *82880970
57
+ version_requirements: *83462720
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &82880300 !ruby/object:Gem::Requirement
60
+ requirement: &83462030 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *82880300
68
+ version_requirements: *83462030
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-bundler
71
- requirement: &82879370 !ruby/object:Gem::Requirement
71
+ requirement: &83460930 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *82879370
79
+ version_requirements: *83460930
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-cucumber
82
- requirement: &82878680 !ruby/object:Gem::Requirement
82
+ requirement: &83460340 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *82878680
90
+ version_requirements: *83460340
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-rspec
93
- requirement: &82877790 !ruby/object:Gem::Requirement
93
+ requirement: &83459550 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *82877790
101
+ version_requirements: *83459550
102
102
  description: Print formatted docs with Winpos WP-800
103
103
  email:
104
104
  - towerhe@gmail.com