Class: Drip::ImmutableDrip::Generator
- Inherits:
-
Object
- Object
- Drip::ImmutableDrip::Generator
- Defined in:
- lib/drip.rb
Instance Attribute Summary collapse
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #add(key, value, *tag) ⇒ Object
- #generate ⇒ Object
-
#initialize(pool = [], tag = []) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(pool = [], tag = []) ⇒ Generator
Returns a new instance of Generator.
566 567 568 569 570 571 |
# File 'lib/drip.rb', line 566 def initialize(pool=[], tag=[]) @pool = pool @tag = tag @shared = Hash.new {|h, k| h[k] = k; k} @tag.each {|pair| @shared[pair[0]]} end |
Instance Attribute Details
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
572 573 574 |
# File 'lib/drip.rb', line 572 def pool @pool end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
572 573 574 |
# File 'lib/drip.rb', line 572 def tag @tag end |
Instance Method Details
#add(key, value, *tag) ⇒ Object
574 575 576 577 578 579 580 |
# File 'lib/drip.rb', line 574 def add(key, value, *tag) @pool << [key, value] idx = @pool.size - 1 tag.uniq.each do |t| @tag << [[@shared[t], key]] end end |
#generate ⇒ Object
582 583 584 585 586 587 588 589 590 |
# File 'lib/drip.rb', line 582 def generate tag = @tag.sort tag.inject(nil) do |last, kv| k = kv[0] k[0] = last if k[0] == last k[0] end ImmutableDrip.new(@pool.sort, tag) end |