Class: Jumon::Subject
- Inherits:
-
Object
- Object
- Jumon::Subject
- Defined in:
- lib/jumon/subject.rb
Instance Attribute Summary collapse
-
#subjects ⇒ Object
readonly
Returns the value of attribute subjects.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #add_subject(var_i, pat_i) ⇒ Object
-
#initialize(base) ⇒ Subject
constructor
A new instance of Subject.
- #set_subjects ⇒ Object
Constructor Details
#initialize(base) ⇒ Subject
Returns a new instance of Subject.
7 8 9 10 11 |
# File 'lib/jumon/subject.rb', line 7 def initialize(base) @template = base[:subject] @variables = base[:variables] @subjects = [@template] end |
Instance Attribute Details
#subjects ⇒ Object (readonly)
Returns the value of attribute subjects.
5 6 7 |
# File 'lib/jumon/subject.rb', line 5 def subjects @subjects end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/jumon/subject.rb', line 5 def template @template end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
5 6 7 |
# File 'lib/jumon/subject.rb', line 5 def variables @variables end |
Instance Method Details
#add_subject(var_i, pat_i) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jumon/subject.rb', line 22 def add_subject(var_i, pat_i) copy = subjects.dup copy.each do |c| result = c.gsub( "{{#{variables[var_i][:name]}}}", variables[var_i][:patterns][pat_i] ) @subjects.push(result) end if pat_i < variables[var_i][:patterns].length - 1 add_subject(var_i, pat_i + 1) elsif var_i < variables.length - 1 add_subject(var_i + 1, 0) end end |
#set_subjects ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/jumon/subject.rb', line 13 def set_subjects return unless variables add_subject(0, 0) @subjects = @subjects.uniq.reject do |s| variables.any? { |v| s.include?("{{#{v[:name]}}}") } end end |