summary_judgement 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -2,14 +2,25 @@ require 'active_support'
2
2
  require 'verbs'
3
3
 
4
4
  module SummaryJudgement
5
+ def self.extended(base)
6
+ def base.inherited(subclass)
7
+ subclass.initialize_summary @summary.dup(subclass)
8
+ end
9
+ end
10
+
5
11
  def summarize(&blk)
6
- @summary = Summary.new(self, &blk)
12
+ @summary ||= Summary.new(self)
13
+ @summary.define(&blk)
7
14
  send :include, InstanceMethods
8
15
  end
9
16
 
10
17
  def summary
11
18
  @summary
12
19
  end
20
+
21
+ def initialize_summary(summary)
22
+ @summary = summary
23
+ end
13
24
  end
14
25
 
15
26
  require 'summary_judgement/summary'
@@ -2,12 +2,15 @@ module SummaryJudgement
2
2
  class Summary
3
3
  attr_reader :term, :adjectives, :modifiers, :subordinates, :base
4
4
 
5
- def initialize(base, &blk)
5
+ def initialize(base, options = {}, &blk)
6
6
  @base = base
7
- @term = base.to_s
8
- @adjectives = []
9
- @modifiers = []
10
- @subordinates = []
7
+ @term = options[:term] || base.to_s
8
+ @adjectives = options[:adjectives] || []
9
+ @modifiers = options[:modifiers] || []
10
+ @subordinates = options[:subordinates] || []
11
+ end
12
+
13
+ def define(&blk)
11
14
  yield self
12
15
  end
13
16
 
@@ -40,6 +43,14 @@ module SummaryJudgement
40
43
  @verb
41
44
  end
42
45
 
46
+ def to_hash
47
+ { :adjectives => @adjectives.dup, :modifiers => @modifiers.dup, :subordinates => @subordinates.dup, :term => @term.dup }
48
+ end
49
+
50
+ def dup(base)
51
+ self.class.new base, to_hash
52
+ end
53
+
43
54
  class << self
44
55
  def render(obj, context)
45
56
  case obj
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{summary_judgement}
8
+ s.version = "1.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andy Rossmeissl"]
12
+ s.date = %q{2009-12-03}
13
+ s.description = %q{Constructs adaptive summaries of object hierarchies based on ActiveRecord associations and other simple relationship structures}
14
+ s.email = %q{andy@rossmeissl.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/summary_judgement.rb",
27
+ "lib/summary_judgement/core_extensions.rb",
28
+ "lib/summary_judgement/descriptor.rb",
29
+ "lib/summary_judgement/instance_methods.rb",
30
+ "lib/summary_judgement/summary.rb",
31
+ "summary_judgement.gemspec",
32
+ "test/helper.rb",
33
+ "test/test_summary_judgement.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/rossmeissl/summary_judgement}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{Dynamic summaries of rich object hierarchies}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_summary_judgement.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ else
51
+ end
52
+ else
53
+ end
54
+ end
55
+
data/test/helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ require 'ruby-debug'
3
4
 
4
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -28,6 +29,12 @@ class Book
28
29
  end
29
30
  end
30
31
 
32
+ class Hardcover < Book
33
+ summarize do |has|
34
+ has.adjective 'hardcover'
35
+ end
36
+ end
37
+
31
38
  class Magazine
32
39
  attr_reader :length_in_pages, :year, :month
33
40
  def initialize(options = {})
@@ -3,6 +3,7 @@ require 'helper'
3
3
  class TestSummaryJudgement < Test::Unit::TestCase
4
4
  def setup
5
5
  @neuromancer = Book.new :book_type => 'novel', :author => 'William Gibson'
6
+ @first_edition_neuromancer = Hardcover.new :book_type => 'novel', :author => 'William Gibson'
6
7
  @where_the_wild_things_are = Book.new :book_type => 'childrens book', :author => 'Maurice Sendak', :pictures => true
7
8
  @current_economist = Magazine.new :year => 2009, :month => "December"
8
9
  @bookshelf = Library.new @neuromancer, @where_the_wild_things_are
@@ -70,4 +71,7 @@ class TestSummaryJudgement < Test::Unit::TestCase
70
71
  assert_equal 'They have a novel by William Gibson', @bedstand.summary(:verbose => :small?, :conjugate => :third, :plurality => :plural, :subject => true)
71
72
  end
72
73
 
74
+ def test_inheritance
75
+ assert_equal 'A hardcover novel by William Gibson', @first_edition_neuromancer.summary
76
+ end
73
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: summary_judgement
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Rossmeissl
@@ -34,6 +34,7 @@ files:
34
34
  - lib/summary_judgement/descriptor.rb
35
35
  - lib/summary_judgement/instance_methods.rb
36
36
  - lib/summary_judgement/summary.rb
37
+ - summary_judgement.gemspec
37
38
  - test/helper.rb
38
39
  - test/test_summary_judgement.rb
39
40
  has_rdoc: true