Class: SummaryJudgement::Summary
- Defined in:
- lib/summary_judgement/summary.rb
Instance Attribute Summary collapse
-
#adjectives ⇒ Object
readonly
Returns the value of attribute adjectives.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#modifiers ⇒ Object
readonly
Returns the value of attribute modifiers.
-
#subordinates ⇒ Object
readonly
Returns the value of attribute subordinates.
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
Class Method Summary collapse
Instance Method Summary collapse
- #adjective(a, options = {}) ⇒ Object
- #aspect(a) ⇒ Object
- #children(*collections_or_symbols) ⇒ Object
- #default ⇒ Object
- #define {|_self| ... } ⇒ Object
- #dup(base) ⇒ Object
- #identity(t = nil, options = {}) ⇒ Object
-
#initialize(base, options = {}, &blk) ⇒ Summary
constructor
A new instance of Summary.
- #modifier(m, options = {}) ⇒ Object
- #options_for_conjugation ⇒ Object
- #placeholder(p) ⇒ Object
- #predicate ⇒ Object
- #tense(t) ⇒ Object
- #to_hash ⇒ Object
- #verb(infinitive) ⇒ Object
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, = {}, &blk) @base = base @terms = [:terms] || [] @adjectives = [:adjectives] || [] @modifiers = [:modifiers] || [] @subordinates = [:subordinates] || [] @verb = [:verb] @aspect = [:aspect] @tense = [:tense] @placeholder = [:placeholder] end |
Instance Attribute Details
#adjectives ⇒ Object (readonly)
Returns the value of attribute adjectives.
3 4 5 |
# File 'lib/summary_judgement/summary.rb', line 3 def adjectives @adjectives end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
3 4 5 |
# File 'lib/summary_judgement/summary.rb', line 3 def base @base end |
#modifiers ⇒ Object (readonly)
Returns the value of attribute modifiers.
3 4 5 |
# File 'lib/summary_judgement/summary.rb', line 3 def modifiers @modifiers end |
#subordinates ⇒ Object (readonly)
Returns the value of attribute subordinates.
3 4 5 |
# File 'lib/summary_judgement/summary.rb', line 3 def subordinates @subordinates end |
#terms ⇒ Object (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, = {}) @adjectives << SummaryJudgement::Descriptor.new(a, ) 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 |
#default ⇒ Object
68 69 70 |
# File 'lib/summary_judgement/summary.rb', line 68 def default @placeholder end |
#define {|_self| ... } ⇒ Object
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, = {}) @terms << SummaryJudgement::Descriptor.new(t || @base.to_s.underscore.humanize.downcase, ) end |
#modifier(m, options = {}) ⇒ Object
29 30 31 |
# File 'lib/summary_judgement/summary.rb', line 29 def modifier(m, = {}) @modifiers << SummaryJudgement::Descriptor.new(m, ) end |
#options_for_conjugation ⇒ Object
60 61 62 |
# File 'lib/summary_judgement/summary.rb', line 60 def { :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 |
#predicate ⇒ Object
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_hash ⇒ Object
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 |