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.
601 602 603 604 605 606 |
# File 'lib/drip.rb', line 601 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.
607 608 609 |
# File 'lib/drip.rb', line 607 def pool @pool end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
607 608 609 |
# File 'lib/drip.rb', line 607 def tag @tag end |
Instance Method Details
#add(key, value, *tag) ⇒ Object
609 610 611 612 613 614 615 |
# File 'lib/drip.rb', line 609 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
617 618 619 620 621 622 623 624 625 |
# File 'lib/drip.rb', line 617 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 |