summary_judgement 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/summary_judgement/instance_methods.rb +23 -1
- data/lib/summary_judgement/summary.rb +12 -2
- data/summary_judgement.gemspec +1 -1
- data/test/helper.rb +6 -0
- data/test/test_summary_judgement.rb +5 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module SummaryJudgement
|
2
2
|
module InstanceMethods
|
3
3
|
def summary(options = {})
|
4
|
-
if children
|
4
|
+
if children and !children.empty?
|
5
5
|
summarize_as_branch(options)
|
6
|
+
elsif !self.class.summary.subordinates.empty?
|
7
|
+
summarize_as_bare_branch(options)
|
6
8
|
elsif term
|
7
9
|
summarize_as_leaf(options)
|
8
10
|
end
|
@@ -70,5 +72,25 @@ module SummaryJudgement
|
|
70
72
|
end.to_sentence
|
71
73
|
end
|
72
74
|
end
|
75
|
+
|
76
|
+
def summarize_as_bare_branch(options = {})
|
77
|
+
result = ''
|
78
|
+
if conjugation = options.delete(:conjugate)
|
79
|
+
options.reverse_merge! :tense => :present, :plurality => :singular
|
80
|
+
case conjugation
|
81
|
+
when String
|
82
|
+
options[:person] ||= :third
|
83
|
+
options[:subject] ||= conjugation
|
84
|
+
when Symbol
|
85
|
+
options[:person] ||= conjugation
|
86
|
+
when TrueClass
|
87
|
+
options[:person] ||= :third
|
88
|
+
end
|
89
|
+
result << Verbs::Conjugator.conjugate(self.class.summary.predicate, options.slice(:person, :subject, :tense, :plurality)).to_s.humanize
|
90
|
+
result << ' '
|
91
|
+
end
|
92
|
+
result << self.class.summary.class.render(self.class.summary.default, self).with_indefinite_article
|
93
|
+
end
|
94
|
+
|
73
95
|
end
|
74
96
|
end
|
@@ -8,6 +8,8 @@ module SummaryJudgement
|
|
8
8
|
@adjectives = options[:adjectives] || []
|
9
9
|
@modifiers = options[:modifiers] || []
|
10
10
|
@subordinates = options[:subordinates] || []
|
11
|
+
@verb = options[:verb]
|
12
|
+
@placeholder = options[:placeholder]
|
11
13
|
end
|
12
14
|
|
13
15
|
def define(&blk)
|
@@ -45,11 +47,19 @@ module SummaryJudgement
|
|
45
47
|
@verb
|
46
48
|
end
|
47
49
|
|
50
|
+
def placeholder(p)
|
51
|
+
@placeholder = p
|
52
|
+
end
|
53
|
+
|
54
|
+
def default
|
55
|
+
@placeholder
|
56
|
+
end
|
57
|
+
|
48
58
|
def to_hash
|
49
|
-
[:adjectives, :modifiers, :subordinates, :terms].inject({}) do |properties, property|
|
59
|
+
[:adjectives, :modifiers, :subordinates, :terms, :verb, :placeholder].inject({}) do |properties, property|
|
50
60
|
val = instance_variable_get :"@#{property}"
|
51
61
|
case val
|
52
|
-
when Symbol
|
62
|
+
when Symbol, NilClass, TrueClass, FalseClass, Fixnum
|
53
63
|
properties[property] = val
|
54
64
|
else
|
55
65
|
properties[property] = val.clone
|
data/summary_judgement.gemspec
CHANGED
data/test/helper.rb
CHANGED
@@ -12,6 +12,7 @@ class TestSummaryJudgement < Test::Unit::TestCase
|
|
12
12
|
@catalog = Catalog.new @bookshelf, @toilet
|
13
13
|
@anne = Librarian.new
|
14
14
|
@seamus = Enthusiast.new
|
15
|
+
@new_releases = Shelf.new # empty!
|
15
16
|
end
|
16
17
|
|
17
18
|
def test_setup
|
@@ -86,4 +87,8 @@ class TestSummaryJudgement < Test::Unit::TestCase
|
|
86
87
|
def test_recursive_send_core_extension
|
87
88
|
assert_equal 'foo bar', 'foo_bar'.recursive_send(:humanize, :downcase)
|
88
89
|
end
|
90
|
+
|
91
|
+
def test_empty_state
|
92
|
+
assert_equal 'You have an empty shelf', @new_releases.summary(:conjugate => :second, :subject => true)
|
93
|
+
end
|
89
94
|
end
|