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.
561 562 563 564 565 566 |
# File 'lib/drip.rb', line 561 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.
567 568 569 |
# File 'lib/drip.rb', line 567 def pool @pool end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
567 568 569 |
# File 'lib/drip.rb', line 567 def tag @tag end |
Instance Method Details
#add(key, value, *tag) ⇒ Object
569 570 571 572 573 574 575 |
# File 'lib/drip.rb', line 569 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
577 578 579 580 581 582 583 584 585 |
# File 'lib/drip.rb', line 577 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 |