Class: SummaryJudgement::Summary

Inherits:
Object
  • Object
show all
Defined in:
lib/summary_judgement/summary.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, options = {}, &blk) ⇒ Summary

Returns a new instance of Summary.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/summary_judgement/summary.rb', line 5

def initialize(base, options = {}, &blk)
  @base = base
  @terms = options[:terms] || []
  @adjectives = options[:adjectives] || []
  @modifiers = options[:modifiers] || []
  @subordinates = options[:subordinates] || []
  @verb = options[:verb]
  @aspect = options[:aspect]
  @tense = options[:tense]
  @placeholder = options[:placeholder]
end

Instance Attribute Details

#adjectivesObject (readonly)

Returns the value of attribute adjectives.



3
4
5
# File 'lib/summary_judgement/summary.rb', line 3

def adjectives
  @adjectives
end

#baseObject (readonly)

Returns the value of attribute base.



3
4
5
# File 'lib/summary_judgement/summary.rb', line 3

def base
  @base
end

#modifiersObject (readonly)

Returns the value of attribute modifiers.



3
4
5
# File 'lib/summary_judgement/summary.rb', line 3

def modifiers
  @modifiers
end

#subordinatesObject (readonly)

Returns the value of attribute subordinates.



3
4
5
# File 'lib/summary_judgement/summary.rb', line 3

def subordinates
  @subordinates
end

#termsObject (readonly)

Returns the value of attribute terms.



3
4
5
# File 'lib/summary_judgement/summary.rb', line 3

def terms
  @terms
end

Class Method Details

.render(obj, context) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/summary_judgement/summary.rb', line 90

def render(obj, context)
  case obj
  when TrueClass, FalseClass, NilClass, String, Fixnum
    obj
  when Array
    if obj.empty?
      nil
    elsif obj.all? { |e| e.is_a? Symbol }
      context.recursive_send(*obj)
    else
      obj.empty? ? nil : obj.map {|o| render o, context}
    end
  when Symbol
    context.send obj
  when Proc
    obj.call context
  end
end

Instance Method Details

#adjective(a, options = {}) ⇒ Object



25
26
27
# File 'lib/summary_judgement/summary.rb', line 25

def adjective(a, options = {})
  @adjectives << SummaryJudgement::Descriptor.new(a, options)
end

#aspect(a) ⇒ Object



56
57
58
# File 'lib/summary_judgement/summary.rb', line 56

def aspect(a)
  @aspect = a
end

#children(*collections_or_symbols) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/summary_judgement/summary.rb', line 33

def children(*collections_or_symbols)
  collections_or_symbols.each do |collection_or_symbol|
    case collection_or_symbol
    when Symbol
      @subordinates << lambda { |parent| parent.send collection_or_symbol }
    else
      @subordinates << collection_or_symbol
    end
  end
end

#defaultObject



68
69
70
# File 'lib/summary_judgement/summary.rb', line 68

def default
  @placeholder
end

#define {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



17
18
19
# File 'lib/summary_judgement/summary.rb', line 17

def define(&blk)
  yield self
end

#dup(base) ⇒ Object



85
86
87
# File 'lib/summary_judgement/summary.rb', line 85

def dup(base)
  self.class.new base, to_hash
end

#identity(t = nil, options = {}) ⇒ Object



21
22
23
# File 'lib/summary_judgement/summary.rb', line 21

def identity(t = nil, options = {})
  @terms << SummaryJudgement::Descriptor.new(t || @base.to_s.underscore.humanize.downcase, options)
end

#modifier(m, options = {}) ⇒ Object



29
30
31
# File 'lib/summary_judgement/summary.rb', line 29

def modifier(m, options = {})
  @modifiers << SummaryJudgement::Descriptor.new(m, options)
end

#options_for_conjugationObject



60
61
62
# File 'lib/summary_judgement/summary.rb', line 60

def options_for_conjugation
  { :tense => @tense, :aspect => @aspect }
end

#placeholder(p) ⇒ Object



64
65
66
# File 'lib/summary_judgement/summary.rb', line 64

def placeholder(p)
  @placeholder = p
end

#predicateObject



48
49
50
# File 'lib/summary_judgement/summary.rb', line 48

def predicate
  @verb
end

#tense(t) ⇒ Object



52
53
54
# File 'lib/summary_judgement/summary.rb', line 52

def tense(t)
  @tense = t
end

#to_hashObject



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/summary_judgement/summary.rb', line 72

def to_hash
  [:adjectives, :modifiers, :subordinates, :terms, :verb, :placeholder, :aspect, :tense].inject({}) do |properties, property|
    val = instance_variable_get :"@#{property}"
    case val
    when Symbol, NilClass, TrueClass, FalseClass, Fixnum
      properties[property] = val
    else
      properties[property] = val.clone
    end
    properties
  end
end

#verb(infinitive) ⇒ Object



44
45
46
# File 'lib/summary_judgement/summary.rb', line 44

def verb(infinitive)
  @verb = infinitive
end