bumbleworks 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,5 +33,24 @@ module Bumbleworks
33
33
  end
34
34
  constant
35
35
  end
36
+
37
+ def tokenize(string)
38
+ return nil if string.nil?
39
+ string = string.gsub(/&/, ' and ').
40
+ gsub(/[ \/]+/, '_').
41
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
42
+ downcase
43
+ end
44
+
45
+ def humanize(string)
46
+ return nil if string.nil?
47
+ tokenize(string).gsub(/_/, ' ').
48
+ gsub(/^\w/) { $&.upcase }
49
+ end
50
+
51
+ def titleize(string)
52
+ return nil if string.nil?
53
+ humanize(string).gsub(/\b('?[a-z])/) { $1.capitalize }
54
+ end
36
55
  end
37
56
  end
@@ -157,8 +157,30 @@ module Bumbleworks
157
157
  })
158
158
  end
159
159
 
160
+ def to_s(options = {})
161
+ titleize(options)
162
+ end
163
+
164
+ def titleize(options = {})
165
+ displayify(:titleize, options)
166
+ end
167
+
168
+ def humanize(options = {})
169
+ displayify(:humanize, options)
170
+ end
171
+
160
172
  private
161
173
 
174
+ def displayify(modifier, options = {})
175
+ task_name = Bumbleworks::Support.send(modifier, nickname)
176
+
177
+ if options[:entity] != false && !(entity_fields = entity_fields(modifier => true)).empty?
178
+ "#{task_name}: #{entity_fields[:type]} #{entity_fields[:identifier]}"
179
+ else
180
+ task_name
181
+ end
182
+ end
183
+
162
184
  def storage_participant
163
185
  self.class.storage_participant
164
186
  end
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.28"
2
+ VERSION = "0.0.29"
3
3
  end
@@ -22,6 +22,21 @@ module Bumbleworks
22
22
  entity_id && entity_type
23
23
  end
24
24
 
25
+ def entity_fields(options = {})
26
+ return {} unless has_entity_fields?
27
+ type = if options[:humanize] == true
28
+ Bumbleworks::Support.humanize(entity_type)
29
+ elsif options[:titleize] == true
30
+ Bumbleworks::Support.titleize(entity_type)
31
+ else
32
+ entity_type
33
+ end
34
+ {
35
+ :type => type,
36
+ :identifier => entity_id
37
+ }
38
+ end
39
+
25
40
  private
26
41
 
27
42
  def entity_id
@@ -59,4 +59,50 @@ describe Bumbleworks::Support do
59
59
  }.to raise_error(NameError)
60
60
  end
61
61
  end
62
+
63
+ describe '.tokenize' do
64
+ it 'creates snake_case version of string' do
65
+ described_class.tokenize('Albus Dumbledore & his_friend').should == 'albus_dumbledore_and_his_friend'
66
+ end
67
+
68
+ it 'uncamelizes' do
69
+ described_class.tokenize('thisStrangeJavalikeWord').should == 'this_strange_javalike_word'
70
+ end
71
+
72
+ it 'returns nil if given nil' do
73
+ described_class.tokenize(nil).should be_nil
74
+ end
75
+ end
76
+
77
+ describe '.humanize' do
78
+ it 'creates humanized version of snaky string' do
79
+ described_class.humanize('mops_are_so_moppy').should == 'Mops are so moppy'
80
+ end
81
+
82
+ it 'created humanized version of camely string' do
83
+ described_class.humanize('thisStrangeJavalikeWord').should == 'This strange javalike word'
84
+ end
85
+
86
+ it 'returns nil if given nil' do
87
+ described_class.humanize(nil).should be_nil
88
+ end
89
+ end
90
+
91
+ describe '.titleize' do
92
+ it 'creates titleized version of snaky string' do
93
+ described_class.titleize('mops_are_so_moppy').should == 'Mops Are So Moppy'
94
+ end
95
+
96
+ it 'created titleized version of camely string' do
97
+ described_class.titleize('thisStrangeJavalikeWord').should == 'This Strange Javalike Word'
98
+ end
99
+
100
+ it 'created titleized version of humany string' do
101
+ described_class.titleize('You are a wonderful toothbrush').should == 'You Are A Wonderful Toothbrush'
102
+ end
103
+
104
+ it 'returns nil if given nil' do
105
+ described_class.titleize(nil).should be_nil
106
+ end
107
+ end
62
108
  end
@@ -672,4 +672,54 @@ describe Bumbleworks::Task do
672
672
  }.to raise_error(Bumbleworks::Task::AvailabilityTimeout)
673
673
  end
674
674
  end
675
+
676
+ describe '#humanize' do
677
+ it "returns humanized version of task name when no entity" do
678
+ task = described_class.new(workflow_item)
679
+ task.humanize.should == 'Go to work'
680
+ end
681
+
682
+ it "returns humanized version of task name with entity" do
683
+ task = described_class.new(workflow_item)
684
+ task[:entity_id] = '45'
685
+ task[:entity_type] = 'RhubarbSandwich'
686
+ task.humanize.should == 'Go to work: Rhubarb sandwich 45'
687
+ end
688
+
689
+ it "returns humanized version of task name without entity if requested" do
690
+ task = described_class.new(workflow_item)
691
+ task[:entity_id] = '45'
692
+ task[:entity_type] = 'RhubarbSandwich'
693
+ task.humanize(:entity => false).should == 'Go to work'
694
+ end
695
+ end
696
+
697
+ describe '#to_s' do
698
+ it "is aliased to #titleize" do
699
+ task = described_class.new(workflow_item)
700
+ task.stub(:titleize).with(:the_args).and_return(:see_i_told_you_so)
701
+ task.to_s(:the_args).should == :see_i_told_you_so
702
+ end
703
+ end
704
+
705
+ describe '#titleize' do
706
+ it "returns titleized version of task name when no entity" do
707
+ task = described_class.new(workflow_item)
708
+ task.titleize.should == 'Go To Work'
709
+ end
710
+
711
+ it "returns titleized version of task name with entity" do
712
+ task = described_class.new(workflow_item)
713
+ task[:entity_id] = '45'
714
+ task[:entity_type] = 'RhubarbSandwich'
715
+ task.titleize.should == 'Go To Work: Rhubarb Sandwich 45'
716
+ end
717
+
718
+ it "returns titleized version of task name without entity if requested" do
719
+ task = described_class.new(workflow_item)
720
+ task[:entity_id] = '45'
721
+ task[:entity_type] = 'RhubarbSandwich'
722
+ task.titleize(:entity => false).should == 'Go To Work'
723
+ end
724
+ end
675
725
  end
@@ -98,4 +98,26 @@ describe Bumbleworks::WorkitemEntityStorage do
98
98
  feh.entity(:reload => true).identifier.should == '15'
99
99
  end
100
100
  end
101
+
102
+ describe "#entity_fields" do
103
+ it 'returns empty hash if no entity' do
104
+ feh = FakeEntityHolder.new
105
+ feh.entity_fields.should == {}
106
+ end
107
+
108
+ it 'returns class name and identifier by default' do
109
+ feh = FakeEntityHolder.new('entity_id' => '15', 'entity_type' => 'LovelyEntity')
110
+ feh.entity_fields.should == { :type => 'LovelyEntity', :identifier => '15' }
111
+ end
112
+
113
+ it 'humanizes class name when requested' do
114
+ feh = FakeEntityHolder.new('entity_id' => '15', 'entity_type' => 'LovelyEntity')
115
+ feh.entity_fields(:humanize => true).should == { :type => 'Lovely entity', :identifier => '15' }
116
+ end
117
+
118
+ it 'titleizes class name when requested' do
119
+ feh = FakeEntityHolder.new('entity_id' => '15', 'entity_type' => 'LovelyEntity')
120
+ feh.entity_fields(:titleize => true).should == { :type => 'Lovely Entity', :identifier => '15' }
121
+ end
122
+ end
101
123
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bumbleworks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: